Highcharts在标签上显示实时价值 [英] Highcharts show real time value on Labels

查看:117
本文介绍了Highcharts在标签上显示实时价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照以下指南创建实时图表:

希望它帮助!


I follow the following guide to create a live chart: http://www.highcharts.com/documentation/how-to-use#live-charts

It catch the values and update the chart every '3' seconds. It works fine!

Now, is it possible to show the real time value on labels? Something like:

This should be change every polling..... Or at least, show the last generated value in other chart place?

This is my HTML/JS code to generate the chart:

    <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>   

解决方案

Here is the link of a topic on how to change legend text dynamically from highcharts forum. [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
Hope it helps!

这篇关于Highcharts在标签上显示实时价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆