2

我想知道如何加载选项和数据图或返回 JSON 对象的整个图结构?

特别是,我想用 JSON 动态创建optionscategories、 axis 、 data 等;我认为这是可能的,但我只找到了描述如何加载数据和系列的信息,而不是选项。

例如,我想定义标题、xAxis 等,返回一个 JSon 对象:

 [...]

  title: {
     text: 'Total fruit consumtion, grouped by gender'
  },
  xAxis: {
     categories: []
  }, 

 [...]

特别是,我需要动态创建一个更复杂的图表,类似于这个:http ://www.highcharts.com/demo/column-stacked-and-grouped

提前致谢!

4

1 回答 1

2

使用DotNet.Highcharts可以根据需要在服务器端创建图表,而无需使用 JavaScript 或 JSON。这是您希望对库执行的示例:

Highcharts chart = new Highcharts("chart")
.InitChart(new Chart { DefaultSeriesType = ChartTypes.Column })
.SetTitle(new Title { Text = "Total fruit consumtion, grouped by gender" })
.SetXAxis(new XAxis { Categories = new[] { "Apples", "Oranges", "Pears", "Grapes", "Bananas" } })
.SetYAxis(new YAxis
            {
                AllowDecimals = false,
                Min = 0,
                Title = new YAxisTitle { Text = "Number of fruits" }
            })
.SetTooltip(new Tooltip { Formatter = "TooltipFormatter" })
.SetPlotOptions(new PlotOptions { Column = new PlotOptionsColumn { Stacking = Stackings.Normal } })
.SetSeries(new[]
            {
                new Series
                {
                    Name = "John",
                    Data = new Data(new object[] { 5, 3, 4, 7, 2 }),
                    Stack = "male"
                },
                new Series
                {
                    Name = "Joe",
                    Data = new Data(new object[] { 3, 4, 4, 2, 5 }),
                    Stack = "male"
                },
                new Series
                {
                    Name = "Jane",
                    Data = new Data(new object[] { 2, 5, 6, 2, 1 }),
                    Stack = "female"
                },
                new Series
                {
                    Name = "Janet",
                    Data = new Data(new object[] { 3, 0, 4, 4, 3 }),
                    Stack = "female"
                }
            });

你可以在这里找到很多 ASP.NET MVC 示例:http: //dotnethighcharts.codeplex.com/releases/view/80650

于 2012-01-29T22:00:13.823 回答