简体   繁体   English

Highcharts-JSON系列数据无法正确显示

[英]Highcharts - JSON series data not showing correctly

I have the following Highcharts sample that I've done in Fiddle as the basis as what I'd want to do using MVC and JSON: Fiddle Link to Example 我有以下在Fi​​ddle中完成的Highcharts示例,作为使用MVC和JSON要做的基础: Fiddle链接至示例

在此处输入图片说明

I'd like to re-create it in MVC using JSON. 我想使用JSON在MVC中重新创建它。 This is the result of my code: 这是我的代码的结果:

在此处输入图片说明

This is definitely wrong as it is only showing the first value of the array and not displaying the rest. 这绝对是错误的,因为它仅显示数组的第一个值,而不显示其余的值。

This is how I'm building the array: 这就是我构建数组的方式:

  Dictionary<string, double[]> columnData = new Dictionary<string, double[]>();
  double[] Array1 = { 49.9, 71.5, 106.4, 129.2 };
  columnData.Add("IE", Array1);

  double[] Array2 = { 83.6, 165, 45, 97.2};
  columnData.Add("FireFox", Array2);

  double[] Array3 = { 92, 125, 32, 83.5 };
  columnData.Add("Chrome", Array3);

  double[] Array4 = { 42.4, 54.2, 55.3, 54.3 };
  columnData.Add("Opera", Array4);

  return Json(columnData.ToArray(), JsonRequestBehavior.AllowGet);

I think that the data is set up properly and the problem is in the javascript code to push the data. 我认为数据设置正确,问题出在JavaScript代码中以推送数据。

jQuery.getJSON("GetColumnChartData", null, function (items) {
    var series = {
                   type: 'column',
                   data: []
                 };

jQuery.each(items, function (itemNo, item) {
               series.data.push([item.Key, parseFloat(item.Value)])
               });

options.series.push(series);

I think I need to loop through the returned "item" to get the other series data. 我想我需要遍历返回的“项目”以获取其他系列数据。 I'm in a brain fart and think that someone may be able to look at it and know what the problem is in a few minutes than the hour that I've already spent trying to fix this. 我陷入了混乱,认为有人可以查看它,并且比我已经花费了数小时试图解决此问题的时间要短几分钟。 After this is done I'll have to change the hard code categories (ie "Educational", "Non-Profit", "Business", "Personal") to be build dynamically. 完成此操作后,我将必须更改硬代码类别(即“教育”,“非盈利”,“业务”,“个人”)以动态构建。 But that's after I get this fixed. 但是那是在我解决了这个问题之后。

Thanks for taking the time to look. 感谢您抽出宝贵的时间查看。

Assuming your data looks something like this: 假设您的数据如下所示:

var items = [
    { 
      name : 'Firefox',
      values : [x, x, x, x]
    },
...
]

jQuery.getJSON("GetColumnChartData", null, function (items) {
    var series = [];
//you could use series = items.map(function(item){...}); 
jQuery.each(items, function (item) {
    series.push({
        name : item.name,
        data : item.values
     });
});
options.series = series;
});

I hope that helps. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM