使用JSON数据绘制Highchart Gauge

SPa*_*dya 8 c# asp.net highcharts

如何使用JSON数据绘制highchart Gauge?

我正在研究高图规格,我在显示数据库的最新数据方面取得了成功.我用JavaScriptSerializer它了

代码是......

  <script type="text/javascript">
    $(function () {
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'gauge',
            plotBackgroundColor: null,
            plotBackgroundImage: null,
            plotBorderWidth: 0,
            plotShadow: false
        }, 
//Other char parameter comes here
}


   function (chart) {
            setInterval(function () {

                $.getJSON("S14.aspx", function (data, textStatus) {
                    console.log(data);
                    $.each(data, function (index, wind) {
                        var point = chart.series[0].points[0],
                        newVal = wind;
                        point.update(newVal);
                    });

                });
            }, 3000);
        });
Run Code Online (Sandbox Code Playgroud)

JSON的代码是

public string chartData1
    {
        get;
        set;

    }
    protected void Page_Load(object sender, EventArgs e)
    {
        List<double> _data = new List<double>();
        GetData();
        foreach (DataRow row in dt.Rows)
        {

            _data.Add((double)Convert.ToDouble(row["S11"]));

        }
        JavaScriptSerializer jss = new JavaScriptSerializer();
        chartData1 = jss.Serialize(_data);

    }
Run Code Online (Sandbox Code Playgroud)

我的JSON看起来像

[1387204961992.4268,72]

那么问题是,仪表盘不会根据我需要刷新页面的最后值移动.我知道这种情况正在发生,因为该GetData功能只执行一次.我被困在这里.

如何根据数据库中的最新值更新来使拨号移动?

SPa*_*dya 3

我认为其中存在错误或其他问题visual studio 2012。我只需将整个代码粘贴到新aspx页面上即可正常工作。我没有做任何其他事情,只是将代码粘贴到另一个页面上。

<script type="text/javascript">


        $(function () {
            $('#container1').highcharts({

                chart: {
                    type: 'gauge',
                    alignTicks: false,
                    plotBackgroundColor: null,
                    plotBackgroundImage: null,
                    plotBorderWidth: 0,
                    plotShadow: false
                },

                title: {
                    text: 'Pressure Meter'
                },

                pane: {
                    startAngle: -150,
                    endAngle: 150
                },

                yAxis: [{
                    min: 0,
                    max: 1000,
                    lineColor: '#339',
                    tickColor: '#339',
                    minorTickColor: '#339',
                    offset: -25,
                    lineWidth: 2,
                    labels: {
                        distance: -20,
                        rotation: 'auto'
                    },
                    tickLength: 5,
                    minorTickLength: 5,
                    endOnTick: false
                }, {
                    min: 0,
                    max: 1000,
                    tickPosition: 'outside',
                    lineColor: '#933',
                    lineWidth: 2,
                    minorTickPosition: 'outside',
                    tickColor: '#933',
                    minorTickColor: '#933',
                    tickLength: 5,
                    minorTickLength: 5,
                    labels: {
                        distance: 12,
                        rotation: 'auto'
                    },
                    offset: -20,
                    endOnTick: false
                }],

                series: [{
                    name: 'Pressure',
                    data: [80],
                    dataLabels: {
                        formatter: function () {
                            var psi = this.y,
                                bar = Math.round(psi / 14.50);
                            return '<span style="color:#339">' + psi + ' psi</span><br/>' +
                                '<span style="color:#933">' + bar + ' bar</span>';
                        },
                        backgroundColor: {
                            linearGradient: {
                                x1: 0,
                                y1: 0,
                                x2: 0,
                                y2: 1
                            },
                            stops: [
                                [0, '#DDD'],
                                [1, '#FFF']
                            ]
                        }
                    },
                    tooltip: {
                        valueSuffix: ' psi'
                    }
                }]

            },
        // Add some life
        function (chart) {
            setInterval(function () {

                $.getJSON("S12.aspx", function (data, textStatus) {

                    $.each(data, function (index, wind) {
                        var point = chart.series[0].points[0],
                        newVal = wind;
                        point.update(newVal);
                    });

                });
            }, 3000);
        });
        });


    </script>
Run Code Online (Sandbox Code Playgroud)