高图表和MVC:如何使用 JSON 加载整个图定义和数据?

发布于 2024-12-26 20:39:33 字数 532 浏览 1 评论 0原文

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

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

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

 [...]

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

 [...]

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

提前致谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如若梦似彩虹 2025-01-02 20:39:33

使用 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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文