public PartialViewResult GetChart() { DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("chart"); //初始化 DotNet.Highcharts.Options.Chart chartOption = new DotNet.Highcharts.Options.Chart(); chartOption.DefaultSeriesType = DotNet.Highcharts.Enums.ChartTypes.Line; chartOption.Width = 400; chartOption.Height = 400; chart.InitChart(chartOption); //设置标题 DotNet.Highcharts.Options.Title title = new DotNet.Highcharts.Options.Title(); title.Align = DotNet.Highcharts.Enums.HorizontalAligns.Center; title.Text = "图表"; chart.SetTitle(title); //提示 DotNet.Highcharts.Options.Tooltip tooltip = new DotNet.Highcharts.Options.Tooltip(); tooltip.ValueSuffix = "摄氏度"; chart.SetTooltip(tooltip); DotNet.Highcharts.Options.PlotOptions plotOptions = new DotNet.Highcharts.Options.PlotOptions(); plotOptions.Bar = new DotNet.Highcharts.Options.PlotOptionsBar(); plotOptions.Bar.DataLabels = new DotNet.Highcharts.Options.PlotOptionsBarDataLabels(); plotOptions.Bar.DataLabels.Enabled = true; chart.SetPlotOptions(plotOptions); //横坐标 DotNet.Highcharts.Options.XAxis xs = new DotNet.Highcharts.Options.XAxis { Categories = new[] { "jan", "feb" } }; List <string> cList = new List <string>(); cList.Add("jan"); cList.Add("feb"); xs.Categories = cList.ToArray(); xs.Title = new DotNet.Highcharts.Options.XAxisTitle(); xs.Title.Text = "月份"; chart.SetXAxis(xs); //纵坐标 DotNet.Highcharts.Options.YAxis ys = new DotNet.Highcharts.Options.YAxis(); ys.Title = new DotNet.Highcharts.Options.YAxisTitle(); ys.Title.Text = "温度"; chart.SetYAxis(ys); //设置表现值 DotNet.Highcharts.Options.Series ss = new DotNet.Highcharts.Options.Series(); List <object> oList = new List <object>(); oList.Add(29); oList.Add(33); ss.Data = new DotNet.Highcharts.Helpers.Data(oList.ToArray()); ss.Name = "温度"; chart.SetSeries(ss); return(PartialView("_PartialChartView", chart)); }
public DotNet.Highcharts.Highcharts GetChart(SimpleChartModel chartModel) { DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts(chartModel.ContainerId); //初始化 DotNet.Highcharts.Options.Chart chartOption = new DotNet.Highcharts.Options.Chart(); chartOption.DefaultSeriesType = chartModel.ChartType; chartOption.Width = chartModel.Width; chartOption.Height = chartModel.Height; chart.InitChart(chartOption); //设置标题 DotNet.Highcharts.Options.Title title = new DotNet.Highcharts.Options.Title(); title.Align = DotNet.Highcharts.Enums.HorizontalAligns.Center; title.Text = chartModel.Title; chart.SetTitle(title); //提示 DotNet.Highcharts.Options.Tooltip tooltip = new DotNet.Highcharts.Options.Tooltip(); tooltip.ValueSuffix = chartModel.ValueSuffix; chart.SetTooltip(tooltip); DotNet.Highcharts.Options.PlotOptions plotOptions = new DotNet.Highcharts.Options.PlotOptions(); plotOptions.Bar = new DotNet.Highcharts.Options.PlotOptionsBar(); plotOptions.Bar.DataLabels = new DotNet.Highcharts.Options.PlotOptionsBarDataLabels(); plotOptions.Bar.DataLabels.Enabled = true; chart.SetPlotOptions(plotOptions); //横坐标 DotNet.Highcharts.Options.XAxis xs = new DotNet.Highcharts.Options.XAxis(); xs.Categories = chartModel.XList.ToArray(); xs.Title = new DotNet.Highcharts.Options.XAxisTitle(); xs.Title.Text = chartModel.XTitle; chart.SetXAxis(xs); //纵坐标 DotNet.Highcharts.Options.YAxis ys = new DotNet.Highcharts.Options.YAxis(); ys.Title = new DotNet.Highcharts.Options.YAxisTitle(); ys.Title.Text = chartModel.YTitle; chart.SetYAxis(ys); //设置表现值 List <DotNet.Highcharts.Options.Series> ssList = new List <DotNet.Highcharts.Options.Series>(); foreach (YSeries yserires in chartModel.SeriesList) { DotNet.Highcharts.Options.Series ss = new DotNet.Highcharts.Options.Series(); ss.Data = new DotNet.Highcharts.Helpers.Data(yserires.YSeriesList.ToArray()); ss.Name = yserires.YName; ssList.Add(ss); } chart.SetSeries(ssList.ToArray()); return(chart); }
private void plotConsolidatedData() { //All data graph DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("chart").InitChart(new Chart { ZoomType = DotNet.Highcharts.Enums.ZoomTypes.X, }) .SetXAxis(new[] { new XAxis { Id = "Month Axes", Categories = datesList, Labels = new XAxisLabels { Step = 15, StaggerLines = 1 } // MinRange=30*24 } //, new XAxis // { // Id="RAM_X", // Type=DotNet.Highcharts.Enums.AxisTypes.Datetime, // // Max=350 // } }); chart.SetTitle(new Title { Text = "Space Weather and Altitude" }); chart.SetSeries(new[] { new Series { YAxis = "Sunspot", XAxis = "Month Axes", Name = "Smoothed SSN", Data = new Data(smoothedSSNList) // PlotOptionsLine=new PlotOptionsLine{PointInterval=24*24*3600000, PointStart=new PointStart(Convert.ToDateTime(datesList[0]))} }, // new Series // { // Name="CPD", // Data = new Data(cpd2), // Color= System.Drawing.Color.Red, // Type=DotNet.Highcharts.Enums.ChartTypes.Columnrange, // XAxis="RAM_X", // YAxis="RAM_Y", // PlotOptionsColumnrange=new PlotOptionsColumnrange{ // Tooltip=new PlotOptionsColumnrangeTooltip{ // PointFormat = "{point.low:%e %b, %y} - {point.high:%e %b, %y}", // HeaderFormat = "<b>{series.name}:</b>{point.y}<br />" //} // } // {PointFormat = "{point.low:%e %b, %y} - {point.high:%e %b, %y}", //HeaderFormat = "<b>{series.name}:</b>{point.x}<br />"}) // }, new Series { XAxis = "Month Axes", YAxis = "Altitude", Name = "Altitude", Data = new Data(altitudeList) }, new Series { XAxis = "Month Axes", YAxis = "Sunspot", Name = "Monthly SSN", Data = new Data(monthlySSNList) }, new Series { XAxis = "Month Axes", YAxis = "Altitude", Name = "Average Dose Values", Data = new Data(avgDoseInAllDataList) } }); chart.SetYAxis(new[] { new YAxis { Id = "Sunspot", Min = 0, Max = 400, TickInterval = 25, Title = new YAxisTitle { Text = "Sunspot Number" } }, new YAxis { Id = "Altitude", Min = 0, Max = 500, TickInterval = 30, Opposite = true, Title = new YAxisTitle { Text = "Altitude [km] and dose values [µGy]" } }, // new YAxis{ // Type=DotNet.Highcharts.Enums.AxisTypes.Linear, // Id="RAM_Y", //} }); ltrChart.Text = chart.ToHtmlString(); }