How to load data from JSON to Highchart?

后端 未结 4 1085
广开言路
广开言路 2021-01-15 06:35

my Json looks like this:

[{\"1332879360000.0\": 300.0, \"1332797760000.0\": 353.0,

\"1332799320000.0\": 358.0, \"1332         


        
4条回答
  •  滥情空心
    2021-01-15 07:30

    I had done that in javascript with JSON..

    "onResultHttpService": function (result, properties) {
    
                var json_str = Sys.Serialization.JavaScriptSerializer.deserialize(result);
                var data = [];
                var cat = [];
    
                var categoryField = properties.PodAttributes.categoryField;
                var valueField = properties.PodAttributes.valueField;
                for (var i in json_str) {
                    var serie = new Array(json_str[i][categoryField], json_str[i][valueField]);
                    var tmpCat = new Array(json_str[i][categoryField]);
                    data.push(serie);
                    cat.push(tmpCat);
                }
                //cat = 'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'
    
                chart = new Highcharts.Chart({
                    chart: {
                        renderTo: properties.id,
                        type: 'column'
                    },
                    title: {
                        text: ''
                    },
                    subtitle: {
                        text: ''
                    },
                    xAxis: {
                        categories: cat
                    },
                    yAxis: {
                        min: 0,
                        title: {
                            text: ''
                        }
                    },
                    legend: {
                        layout: 'vertical',
                        backgroundColor: '#FFFFFF',
                        align: 'left',
                        verticalAlign: 'top',
                        x: 100,
                        y: 70,
                        floating: true,
                        shadow: true
                    },
                    tooltip: {
                        formatter: function () {
                            return '' +
                        this.x + ': ' + this.y + ' mm';
                        }
                    },
                    plotOptions: {
                        column: {
                            pointPadding: 0.2,
                            borderWidth: 0
                        }
                    },
                    series: [{ data: data}]
                });
    
    
            }
    
        };
    

提交回复
热议问题