A Logarithmic Scale is a nonlinear scale that is very useful when plotting different scientific or mathematical data. Given example shows Column Chart with Logarithmic Axis along with source code that you can try running locally.
@{ Layout = null; } <!DOCTYPE HTML> <html> <head> <script> window.onload = function () { var chart = new CanvasJS.Chart("chartContainer", { animationEnabled: true, theme: "dark2", // "light1", "light2", "dark1", "dark2" title: { text: "Distance of Planets from Sun" }, subtitles: [{ text: "Logarithmic Y-Axis", fontSize: 18 }], axisY: { title: "Distance (in million miles)", logarithmic: true }, data: [{ type: "column", indexLabelFontColor: "white", indexLabel: "{y}", indexLabelFontSize: 16, yValueFormatString: "#,##0.# mn", toolTipContent: "<b>{label}: {y}</b> miles", dataPoints: @Html.Raw(ViewBag.DataPoints) }] }); chart.render(); } </script> </head> <body> <div id="chartContainer" style="height: 370px; width: 100%;"></div> <script src="https://cdn.canvasjs.com/canvasjs.min.js"></script> </body> </html>
using ASPNET_MVC_ChartsDemo.Models; using Newtonsoft.Json; using System.Collections.Generic; using System.Web.Mvc; namespace ASPNET_MVC_ChartsDemo.Controllers { public class HomeController : Controller { // GET: Home public ActionResult Index() { List<DataPoint> dataPoints = new List<DataPoint>(); dataPoints.Add(new DataPoint("Mercury", 36)); dataPoints.Add(new DataPoint("Venus", 67.2)); dataPoints.Add(new DataPoint("Earth", 93)); dataPoints.Add(new DataPoint("Mars", 141.6)); dataPoints.Add(new DataPoint("Jupiter", 483.6)); dataPoints.Add(new DataPoint("Saturn", 886.7)); dataPoints.Add(new DataPoint("Uranus", 1784)); dataPoints.Add(new DataPoint("Neptune", 2794.4)); ViewBag.DataPoints = JsonConvert.SerializeObject(dataPoints); return View(); } } }
using System; using System.Runtime.Serialization; namespace ASPNET_MVC_ChartsDemo.Models { //DataContract for Serializing Data - required to serve in JSON format [DataContract] public class DataPoint { public DataPoint(string label, double y) { this.Label = label; this.Y = y; } //Explicitly setting the name to be used while serializing to JSON. [DataMember(Name = "label")] public string Label = ""; //Explicitly setting the name to be used while serializing to JSON. [DataMember(Name = "y")] public Nullable<double> Y = null; } }
logarithmicBase property can be used to customize the base of the logarithmic scale. Some other commonly used customization options include logarithmic, reversed, etc.
Note For step by step instructions, follow our ASP.NET MVC Integration Tutorial