Highcharts为x轴分组的类别解析json字符串

时间:2018-01-30 06:46:06

标签: javascript json highcharts

我正在使用asp c#开发项目并使用Highcharts进行报告。

我想将我拥有的类别分组为json字符串,但我不知道如何将数据推送到x轴类别。

  

[{       " name":" CTS",       "类别":[" 01AT"," 02AT"," 03AT"," 04AT"," 06AT"]   },{       " name":" 340_HSC",       "类别":[" 02QHSC"," 05QHSC"," 07QHSC"," 14QHSC"]   }]

1 个答案:

答案 0 :(得分:0)

您的json字符串包含要传递为xAxis类别的正确数据格式。 所以将你的json字符串传递给

$(function () {

var jsond=[{ "name": "CTS", "categories": ["01AT", "02AT", "03AT", "04AT", "06AT"] }, { "name": "340_HSC", "categories": ["02QHSC", "05QHSC", "07QHSC", "14QHSC"] }];

    var chart = new Highcharts.Chart({
        chart: {
            renderTo: "container",
            type: "column"
        },
        title: {
            useHTML: true,
            x: -10,
            y: 8,
            text: '<span class="chart-title"> Grouped categories <span class="chart-href"> <a href="http://www.blacklabel.pl/highcharts" target="_blank"> Black Label </a> </span> <span class="chart-subtitle">plugin by </span></span>'
        },
        series: [{
            data: [4, 14, 18, 5, 6, 5, 14, 15, 18]
        }],
        xAxis: {
            categories: jsond
        }
    });
});

Fiddle演示