addPoint使用highcharts(javascript)

时间:2013-02-21 14:05:03

标签: javascript highcharts

我已经开始使用highcharts.js,但无法在条形图中添加新点: 每次进入addPoint,Firefox冻结:( 我正在使用Firebug,当它尝试添加点时,它总是冻结:(

// if no graph
if (! charts[0])
{
    // make chart table
    var round_ids = [];
    var total_players = [];
    var total_bets = [];
    $.each(last_rounds_cache.last_rounds_data, function(index, value)
        {
            round_ids.push(Number(value[0]));
            total_players.push(Number(value[2]));
            total_bets.push(Number(value[3]));
        }
    )

    charts[0] = new Highcharts.Chart({
        chart: {
            renderTo: 'players_per_round',
            type: 'column',
            events: {
                click: function(e) {
                    // find the clicked values and the series
                    var x = e.xAxis[0].value,
                        y = e.yAxis[0].value,
                        series = this.series[0];

                    // Add it
                    series.addPoint([x, y]);

                }
            }
        },
        title: {
            text: 'Players/Bets per Round'
        },
        xAxis: {
            categories: round_ids,
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Rainfall (mm)'
            }
        },
        legend: {
            layout: 'vertical',
            backgroundColor: '#FFFFFF',
            align: 'left',
            verticalAlign: 'top',
            x: 10,
            y: 10,
            floating: false,
            shadow: true
        },
        tooltip: {
            formatter: function() {
                return ''+
                    this.x +': '+ this.y;
            }
        },
        plotOptions: {
            column: {
                pointPadding: 0.2,
                borderWidth: 0
            }
        },
        series: [{
            name: 'Players',
            data: total_players
        }, {
            name: 'Bets',
            data: total_bets
        }]
    });
}
else
{
    if (newChartsPoints.length > 0)
    {


        $.each(newChartsPoints, function(index, value)
        {
            // retreive data
            var temp_round_id = value[0];
            var temp_total_players = value[1][0];
            var temp_total_bets = value[1][1];

            // add points
            var series = charts[0].series;
            series[0].addPoint([temp_round_id, temp_total_players], false);
            series[1].addPoint([temp_round_id, temp_total_bets], false);

            // add categories
            categories = charts[0].xAxis[0].categories;
            categories.push(temp_round_id);
            charts[0].xAxis[0].setCategories(categories, false);
            charts[0].redraw();
        });
    }
}

0 个答案:

没有答案