开发者

problem with highcharts series option

Hi i am having problem with my highcharts 'series' options. i initialized the chart options as below:

            var options = {
            chart: {
                renderTo: 'chart',
                defaultSeriesType: 'line',
            },
            title: {
                text: 'Weight Monitor',
            },
            xAxis: {
                title: {
                    text: 'Date Measurement'
                },
                categories: []
            },
            yAxis: {
                title: {
                    text: 'Weight (in Lbs)'
                }
            },
            series: []
    };

I kept the categories: [] blank so that i can put the values in categories later. Same thing i did with my series options. I kept the data:[] as blank to fill it later. Now i wrote the code to fill the data.

                var lines = [
                [2011,150],
                [2012,121],
开发者_Go百科        $.each(lines, function(lineNo, line) {
            var items = line.toString().split(",");
            $.each (items, function(itemNo, item) {

                if(itemNo == 0){
                    alert("itemNo: " + itemNo + " item: " + item);
                    options.xAxis.categories.push(item);
                    alert(options.xAxis.categories);
                }

                else {
                            var series = {
                                    data: []
                            };
                    alert("itemNo: " + itemNo + " item: " + item);
                    options.series.data.push(parseFloat(item));
                    alert(options.series.data);
                };
            });
        });
        var chart = new Highcharts.Chart(options);

Now when i execute this code, my categories[] is getting values properly, but the execution gets stuck when it is at "options.series.data.push(parseFloat(item))". I am getting the proper value in the "alert("itemNo: " + itemNo + " item: " + item);". but just after that it hangs while pushing the item in series.data[]

any idea what is the problem. and i am running this javascript in php project so don't know if there is any issue because of the language. thanks


The problem is options.series.data.push(parseFloat(item)).

If you look at your options object, you can see that your series array is empty. You can ad series object in your options definition as follows -

series: [{
    data: []
}]

Also the line

var series = {
    data: []
};

is of no use.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜