我正在使用 dotnet 高图表和 asp.net mvc3。我在向样条图添加多个系列时遇到问题。
这段代码基本上每秒更新一次图表。
这适用于一个数据系列。但我需要添加多个数据系列。
请帮助我为此代码添加多个系列。
提前致谢
public ActionResult SplineUpdateEachSecond()
{
List<object> points = new List<object>(20);
DateTime now = DateTime.Now;
Random rand = new Random();
for (int i = -19; i <= 0; i++)
points.Add(new { X = now.AddSeconds(i), Y = rand.NextDouble() });
Highcharts chart = new Highcharts("chart")
.SetOptions(new GlobalOptions { Global = new Global { UseUTC = false } })
.InitChart(new Chart
{
DefaultSeriesType = ChartTypes.Spline,
MarginRight = 10,
Events = new ChartEvents
{
Load = "ChartEventsLoad"
}
})
.AddJavascripFunction("ChartEventsLoad",
@"// set up the updating of the chart each second
var series = this.series[0];
setInterval(function() {
var x = (new Date()).getTime(), // current time
y = Math.random();
series.addPoint([x, y], true, true);
}, 1000);")
.SetTitle(new Title { Text = "Live random data" })
.SetXAxis(new XAxis
{
Type = AxisTypes.Datetime,
TickPixelInterval = 150
})
.SetYAxis(new YAxis
{
Title = new YAxisTitle { Text = "Value" },
PlotLines = new[]
{
new YAxisPlotLines
{
Value = 0,
Width = 1,
Color = ColorTranslator.FromHtml("#808080")
}
}
})
.SetTooltip(new Tooltip { Formatter = "TooltipFormatter" })
.AddJavascripFunction("TooltipFormatter",
@"return '<b>'+ this.series.name +'</b><br/>'+
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
Highcharts.numberFormat(this.y, 2);")
.SetLegend(new Legend { Enabled = false })
.SetExporting(new Exporting { Enabled = false })
.SetSeries(new Series
{
Name = "Random data",
Data = new Data(points.ToArray())
});
return View(chart);
}