0

我的目标是使用 API 创建动态图表:http: //api.highcharts.com/highcharts#Series

方法:setData (Array<Mixed> data, [Boolean redraw])

但是,我在更新图表时遇到了一些问题:

                series: [{
                            name: 'Lunch',
                            data: [49.9, 71.5, 106.4, 129.2, 144.0, 

                                            176.0, 135.6]

                        }, {
                            name: 'Dinner',
                            data: [83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 

                                               105.0]

                        }]
                    });
                });

                    // the button action
                $('#button').click(function() {
                    var chart = $('#container').highcharts();
                    chart.series[0].setData([129.2, 144.0, 176.0, 

                                135.6, 148.5, 216.4, 194.1] );
                });

                    </script>
            </head>
            <body>
                <script src="js/highcharts.js"></script>
                <script src="js/modules/exporting.js"></script>

                <div id="container"
                    style="min-width: 400px; height: 400px; 



                                margin: 0 auto"></div>
                <button id="button">Update the data</button>
            </body>
            </html>

请告知使用该setData (Array<Mixed> data, [Boolean redraw])方法的适当方法是什么?

4

1 回答 1

0

检查这个jsFiddle看看应该如何实现动态高图。您应该使用该load函数动态加载数据。例子:

events: {
                load: function() {

                    // set up the updating of the chart each second
                    var series = this.series[0];
                    setInterval(function() {
                        var x = (new Date()).getTime(), // current time
                            y = Math.random();
                        series.addPoint([x, y], true, true);
                    }, 1000);
                }
            }
于 2013-05-07T06:38:43.923 回答