Emile Bodin
Emile Bodin

Reputation: 31

highchart json data points

I am breaking my head over this one.

i have an highchart with Json data. now would like to split the Json data in to 2 data points.

json data;
[1340283205000,5,32]

Explanation
time, number, number

The current chart works with time, number. Now i have added another datapoint but that dows not work.

function requestData() {
        $.ajax({
            url: 'php/hits_json.php', 
            success: function(point) {
                var series = chart1.series[0],
shift = series.data.length > 20; // shift if      the series is longer than 20

                // add the point
                chart1.series[0].addPoint(eval(point), true, shift);

                // call it again after one second
                setTimeout(requestData, 5000);  
            },
            cache: false
        });
    }

    $(document).ready(function() {
        window.chart1 = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                defaultSeriesType: 'areaspline',
                events: {
                    load: requestData
                }
            },
            title: {
                text: 'Hits per 5 sec'
            },
            xAxis: {
                type: 'datetime',
                tickPixelInterval: 100,
                maxZoom: 10 * 10000
            },
            yAxis: {
                min: 0,
                minPadding: 0.25,
                maxPadding: 0.1,
                title: {
                    text: 'Hits',
                    margin: 40
                }
            },
    plotOptions: {
                series: {
                    dataLabels: {
                        enabled: true
                            },
                    marker: {
                        enabled: true
                            },
                        }
                    },
        credits: {
                enabled: false
                    },
            series: 

            [{
                name: 'Hits',

                data: [0],lineWidth: 1
            },{
                        name: 'Requests',
                        data: [0],lineWidth: 1
            }]
        });     
    });

Can someone point me in the right direction to solve my issue :)

Thnx in advance

Upvotes: 1

Views: 1261

Answers (1)

Linger
Linger

Reputation: 15048

You do not have the data labeled in your json. So the first two values are treated as x and y and the third is ignored. To properly format your data do something like the following:

var json = [
{
  "x":1340283205000,
  "y":5
}, 
{
  "x":1340283205000,
  "y":32
}];

Upvotes: 2

Related Questions