数组作为Highcharts系列不起作用

时间:2015-06-24 13:56:32

标签: javascript jquery highcharts highstock

我在尝试将数组作为参数传递给highcharts时遇到问题。 我是following - (Gowri's)的建议,但我没有运气。即使在我的图例中正确呈现了用户名(有意消失的姓氏),但实际值完全错过了,因此我的图表总是空的,即没有栏...

http://i.stack.imgur.com/aqErt.png

即使数组已正确填充,并且图例中的用户名显示正常,但它没有显示任何内容

http://i.stack.imgur.com/iCA60.png

我也在jsfiddle上发布了一个示例,但很抱歉没有正确呈现

jsfiddle(包括json2来源)

HTML:

<script src="http://code.highcharts.com/highcharts.js"></script>
<center>
    <div id='searchdiv'></div>
    <script type='text/javascript'>
        setTimeout(function() {
            Chart_Weekly_Trends_Bar('weeklypackagingtrends', 'Passed Approval', ['03/01/2014', '10/01/2014', '17/01/2014', '24/01/2014', '31/01/2014', '07/02/2014', '14/02/2014', '21/02/2014', '28/02/2014', '07/03/2014'], 'Number of Apps', 'No of Apps', ['Andr', 'Ch', 'Gra', 'Gul', 'Hora', 'Jhan', 'Krist', 'Man', 'Mike', 'Phil', 'Tris'], ['0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,1,2,1,0,2', '0,0,0,0,0,0,0,0,0,0', '0,0,0,2,0,0,0,0,0,0', '0,0,0,0,2,1,0,0,2,1', '0,0,0,0,0,0,0,0,0,0'])
        }, 100);
    </script>

Javascript:

function Chart_Weekly_Trends_Bar(DIVID, TITLE, CATEGORIES, yAxisLabel, Tooltip, ANALYSTS_NAMES, ANALYSTS_DATA) {
    var Param_CATEGORIESS = JSON.stringify(CATEGORIES);
    var data_CATEGORIESS = JSON.parse(Param_CATEGORIESS);

    var arr = [];

    for (var i = 0; i < ANALYSTS_NAMES.length; i++) {
        arr[i] = {};
        arr[i]['name'] = ANALYSTS_NAMES[i]; //Here push your series name field in your example "John, Jane etc"
        arr[i]['data'] = ANALYSTS_DATA[i]; //Here push your series name field in your example "John, Jane etc"
    }
    //arr = arr;
    var Param_arr = JSON.stringify(arr);
    var data_arr = JSON.parse(Param_arr);

    $("#" + DIVID).highcharts({
        chart: {
            type: 'column',
            height: 450,
            width: 800,
            renderTo: 'weeklypackagingtrends'
        },
        title: {
            text: TITLE
        },
        xAxis: {
            categories: data_CATEGORIESS,
            //categories: ['20-10-2015','21-10-2015'],
            tickInterval: .5,
            tickmarkPlacement: 'on',
            gridLineWidth: .5,
            min: 0,
            max: 9,
            labels: {
                style: {
                    fontSize: '9px'
                }
            }
        },
        yAxis: {
            opposite: true,
            min: 0,
            title: {
                text: yAxisLabel
            }
        },
        tooltip: {
            headerFormat: '<span style="font-size:20px">{point.key}</span><table width=150px>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                '<td style="padding:0"><b>{point.y:1f} </b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true,
            animation: true
        },
        plotOptions: {
            column: {
                pointPadding: 0.2,
                borderWidth: 0
            }
        },
        scrollbar: {
            enabled: true
        },
        series: data_arr,
        navigation: {
            buttonOptions: {
                verticalAlign: 'bottom',
                y: -20,
                height: 30,
                theme: {
                    'stroke-width': 1,
                    stroke: 'silver',
                    r: 0,
                    states: {
                        hover: {
                            fill: '#bada55'
                        },
                        select: {
                            stroke: '#039',
                            fill: '#bada55'
                        }
                    }
                }
            }
        },
        credits: {
            enabled: false
        }
    });
}

1 个答案:

答案 0 :(得分:0)

您当前正在将数据数组作为字符串数组发送:

['0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,1,2,1,0,2', '0,0,0,0,0,0,0,0,0,0', '0,0,0,2,0,0,0,0,0,0', '0,0,0,0,2,1,0,0,2,1', '0,0,0,0,0,0,0,0,0,0']

您需要的是一组数组:

[[0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,1,2,1,0,2], [0,0,0,0,0,0,0,0,0,0], [0,0,0,2,0,0,0,0,0,0], [0,0,0,0,2,1,0,0,2,1], [0,0,0,0,0,0,0,0,0,0]]

示例: