Question

I'd like to know how it is possible to load options & data graph or whole graph structure returning a JSON object?

In particular, I'd like to dynamically create options, categories, axis, data, etc. with JSON; I think it is possible, but I only found informations describing how to load data& series, not options.

For example, I'd like to define title, xAxis, etc, returning a JSon Object:

 [...]

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

 [...]

In particular, I need to dynamically create a more complex graph, similar to this one: http://www.highcharts.com/demo/column-stacked-and-grouped

Thanks in advance!

Was it helpful?

Solution

With DotNet.Highcharts is possible to create the chart on the server side as you like without using JavaScript or JSON. Here is the example which you would like do with the library:

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"
                }
            });

You can find a lot of ASP.NET MVC examples here: http://dotnethighcharts.codeplex.com/releases/view/80650

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top