0

我正在尝试使用如下高图生成多轴图。但它不起作用,数组生成和一切都很好。

如果我硬编码totalNoOfLabels然后totalLabelsSize它的工作。请建议:

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

$(function () {
var result=[{"date":"2013-05-01","propertiesList":   {"labelsCount":"14","totalSize":"62.62"}},{"date":"2013-05-04","propertiesList":{"labelsCount":"4","totalSize":"22.43"}},{"date":"2013-05-03","propertiesList":{"labelsCount":"7","totalSize":"34.09"}},{"date":"2013-05-02","propertiesList":{"labelsCount":"13","totalSize":"67.51"}},{"date":"2013-05-05","propertiesList":{"labelsCount":"3","totalSize":"11.65"}}];

var totalNoOfLabels=[];
var totalLabelsSize=[];
var dates=[];

dailyStatList = JSON.stringify(result);             
            var statsObj = $.parseJSON(dailyStatList);
            $.each(statsObj, function() {
                dates.push(this.date);
                    totalNoOfLabels.push(this.propertiesList.labelsCount);
                totalLabelsSize.push(this.propertiesList.totalSize);
            });

    $('#container').highcharts({
        chart: {
            zoomType: 'xy'
        },
        title: {
            text: 'Info'
        },

        xAxis: [{
            categories: dates
        }],
        yAxis: [{ // Primary yAxis
            labels: {

                style: {
                    color: '#89A54E'
                }
            },
            title: {
                text: 'No of labels',
                style: {
                    color: '#89A54E'
                }
            }
        }, { // Secondary yAxis
            title: {
                text: 'Size ',
                style: {
                    color: '#4572A7'
                }
            },
            labels: {

                style: {
                    color: '#4572A7'
                }
            },
            opposite: true
        }],
        tooltip: {
            shared: true
        },
        legend: {
            layout: 'vertical',
            align: 'left',
            x: 120,
            verticalAlign: 'top',
            y: 100,
            floating: true,
            backgroundColor: '#FFFFFF'
        },
        series: [{
            name: 'Labels',
            color: '#4572A7',
            type: 'column',
            yAxis: 1,
            data: totalNoOfLabels


        }, {
            name: 'Size',
            color: '#89A54E',
            type: 'spline',
            data: totalLabelsSize

        }]
     });
  });  
4

1 回答 1

0

labelsCount并且totalSize应该是数字,而不是字符串。解析该值,或将 JSON 作为数字放入,并且将正常工作。

于 2013-08-01T11:38:35.917 回答