|
|
Controller Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Highsoft.Web.Mvc.Charts;
namespace MVC_Demo.Areas.Highcharts.Controllers.Shared
{
public partial class SharedController : Controller
{
public ActionResult LineLog()
{
List<double> logValues = new List<double> { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 };
List<LineSeriesData> logData = new List<LineSeriesData>();
logValues.ForEach(p => logData.Add(new LineSeriesData { Y = p }));
ViewData["logData"] = logData;
return View();
}
}
}
Controller Code
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
@using Highsoft.Web.Mvc.Charts
@using Highsoft.Web.Mvc.Charts.Rendering
@{ var chartOptions =
new Highcharts
{
Chart = new Highsoft.Web.Mvc.Charts.Chart
{
Type = ChartType.Line
},
Title = new Title
{
Text = "Logarithmic axis demo"
},
XAxis = new List<XAxis>
{
new XAxis
{
TickInterval = 1
}
},
YAxis = new List<YAxis>
{
new YAxis
{
Type = "logarithmic"
//MinorTickIntervalNumber = 0.1
}
},
Tooltip = new Tooltip
{
HeaderFormat = "<b>{series.name}</b><br />",
PointFormat = "x = {point.x}, y = {point.y}"
},
Series = new List<Series>
{
new LineSeries
{
Data = @ViewData["logData"] as List<LineSeriesData>,
PointStart = 1
}
}
};
chartOptions.ID = "chart";
var renderer = new HighchartsRenderer(chartOptions);
}
@Html.Raw(renderer.RenderHtml())