0

我按照以下指南创建实时图表: http ://www.highcharts.com/documentation/how-to-use#live-charts

它捕获值并每 '3' 秒更新一次图表。它工作正常!

现在,是否可以在标签上显示实时值?就像是: 在此处输入图像描述

这应该改变每次轮询.....或者至少,在其他图表位置显示最后生成的值?

这是我生成图表的 HTML/JS 代码:

    <script type="text/javascript">
    var chart; // global

    function requestData() {
        $.ajax({
            url: 'live-server-data.php', 
            success: function(point) {
                var series = chart.series[0],
                    shift = series.data.length > 30; // shift if the series is longer than 20
                var series = chart.series[1],
                    shift = series.data.length > 30; // shift if the series is longer than 20
                var series = chart.series[2],
                    shift = series.data.length > 30; // shift if the series is longer than 20

                // add the point
                chart.series[0].addPoint([point[0], point[1]], true, shift);
                chart.series[1].addPoint([point[0], point[2]], true, shift);
                chart.series[2].addPoint([point[0], point[3]], true, shift);

                setTimeout(requestData, 3000);  
            },
            cache: false
        });
    }


    $(document).ready(function() {
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                defaultSeriesType: 'spline',
                events: {
                    load: requestData
                }
            },
            title: {
                text: 'Live data'
            },
            xAxis: {
                type: 'datetime',
                tickPixelInterval: 150,
                maxZoom: 40 * 1000
            },
            yAxis: {
                minPadding: 0.5,
                maxPadding: 0.5,
                showLastLabel: true,
                title: {
                    text: '',
                    margin: 1
                }
            },
        tooltip: {
            formatter: function() {
                    return '<b>'+ this.series.name +'</b><br/>'+
                    Highcharts.dateFormat('%H:%M:%S', this.x) +'<br/>'+
                    'MDA: '+ this.y;
            }
        },
            series: [{
                name: 'Point1',
                data: []
            }, {
                name: 'Point2',
                data: []
            }, {
                name: 'Point3',
                color: '#FF00FF',
                data: []
            }]
        });     
    });     
    </script>   
4

1 回答 1

1

这是有关如何从 highcharts 论坛动态更改图例文本的主题链接。[http://highslide.com/forum/viewtopic.php?f=9&t=18805&p=76061&hilit=change+series+name#p76061][1]

[1]:http
://highslide.com/forum/viewtopic.php?f=9&t=18805&p=76061&hilit=change%20series%20name#p76061希望对您有所帮助!

于 2012-07-09T06:59:53.350 回答