score:3

Accepted answer

i think there is a bug or something in the visual studio 2012 . i just paste the entire code on the new aspx page it it got working. i have not done anything else i just pasted the code on another page.

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

score:2

in order for the chart to update, the browser somehow needs to request the latest data from the server. there are two ways it can do this:

  1. a page refresh - the whole page is fetched again, with the latest data.
  2. an ajax request. this makes a request for just the data, without re-loading the entire page.

i presume you would like to update the chart without reloading the entire page. in order do to this, you need to find out about making ajax requests using jquery.

the highcharts site has some resources which will help you (e.g. http://www.highcharts.com/docs/working-with-data/preprocessing-live-data). you need to learn how to make an ajax call in javascript, and use the returned data to update your chart. you will also need to write the server side part which returns the ajax data. the example given is in php, but it should be fairly straight forward to do something similar in asp.net.

score:3

try to place this part of code

setinterval(function() {
    $(function() {
    $.getjson('s12.aspx', function(data) {
        $.each(data, function(val) {
        if (val !== null)
        {
        var point = chart.series[0].points[0];
            point.update(val);
        }
        });
    });
    })
},2000)

inside callback chart, like here: http://www.highcharts.com/demo/gauge-speedometer

if you receive any errors,please attach.


Related Query

More Query from same tag