highcharts - 点击后将系列添加到图表中

时间:2013-11-24 16:15:20

标签: javascript jquery highcharts

我通过highcharts得到了图表。这是我到那里的系列。

series: [{
                name: 'Математика',
                data: [<?php echo $mathFirst; ?>, <?php echo $mathSecond; ?>, <?php echo $mathThird; ?>, <?php echo $mathFourth; ?>, <?php echo $mathFifth; ?>]
            }, {
                name: 'Программирование',
                data: [<?php echo $programmingFirst; ?>, <?php echo $programmingSecond; ?>, <?php echo $programmingThird; ?>, <?php echo $programmingFourth; ?>, <?php echo $programmingFifth; ?>]
            }, {
                name: 'Английский язык',
                data: [<?php echo $englishFirst; ?>, <?php echo $englishSecond; ?>, <?php echo $englishThird; ?>, <?php echo $englishFourth; ?>, <?php echo $englishFifth; ?>]
            }, {
                name: 'История',
                data: [<?php echo $historyFirst; ?>, <?php echo $historySecond; ?>, <?php echo $historyThird; ?>, <?php echo $historyFourth; ?>, <?php echo $historyFifth; ?>]
            }, {
                name: 'Все предметы',
                data: [<?php echo $middleFirst; ?>, <?php echo $middleSecond; ?>, <?php echo $middleThird; ?>, <?php echo $middleFourth; ?>, <?php echo $middleFifth; ?>]
            }]

我有一个选择。

<select>
        <option value="all">Все предметы</option>
        <option value="math">Математика</option>
        <option value="programming">Программирование</option>
        <option value="english">Английский язык</option>
        <option value="history">История</option>
    </select>

当点击任何选项时,它应该将一个系列添加到带有一些值的图形中。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

以下是从<select>元素的onChange事件中添加数据的快速示例:

// the select handler
$('#select').change(function() {
    var chart = $('#container').highcharts();
    someData = [];
    for (var i = 0; i < 12; i++){
        someData.push(Math.random() * 250);
    }
    chart.addSeries({
        data: someData
    });
});

小提琴here