Aleksander Korovin
Aleksander Korovin

Reputation: 349

All series data are equal highcharts

I have function for updating sensors. Idea is simple, i add new points from sensors (1 sensor = 1 line) and after appending I update charts. But something went wrong and all series equal to themself

seriesArr - just array of sensors like {"sensorId1", sensorId2 etc}

chartObj - object of charts like chart 1: { chart: highcharts, seriesArr: seriesArr }

Simple explanations:

chartObject.chart.series[0].points = chartObject.chart.series[1].points = chartObject.chart.series[2].points = etc

My code:

 updateAllCharts: function() {
        var allCharts = this.charts;
        console.log('charts');
        for (var chart in allCharts) {
            var chartObject = allCharts[chart];
            for (var i = 0; i < chartObject.seriesArr.length; i++) {
                var elemId = chartObject.seriesArr[i][0];
                var val = this.sensors[elemId].get('value');
                console.log(val);
                if (val === undefined) { // if sensor cant get data
                    continue;
                }
                var now = new Date;
                var x = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(),
                    now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds(), now.getUTCMilliseconds());
                var y = parseFloat(val);
                chartObject.chart.series[i].addPoint([x, y], false, false);
                console.log(x, y);
                console.log(chartObject.chart.series[i].data);
            }

        }
        for (var chart in allCharts) {
            var chartObject = allCharts[chart];
            chartObject.chart.redraw();
        }

    }

Screen:

Same series

UPDATE:

ProcessedDataX and Y arrays are changing, but there problem with points array, I always get some weird (maybe cached) points. WTF.

Playground

If you wanna play, i've setted up here jsfiddle, but actually it probably doesn't work. Can't add points to highchart object with setInterval.

JSFIDDLE

UPDATE2:

Actually it works fine in jsfiddle but i don't know wtf is going on in my project.

UPDATE3:

Found, that the same last point adds to each series. For example, series[i].lastPoints = series[n] , where n = last iteration.

Upvotes: 0

Views: 167

Answers (2)

Sebastian Bochan
Sebastian Bochan

Reputation: 37588

To all chart.redraw() you need to set isDirty flag

so try to use this code:

for (var chart in allCharts) {
        var chartObject = allCharts[chart];
        chartObject.yAxis[0].isDirty = true;
        chartObject.chart.redraw();
}

Upvotes: 0

Aleksander Korovin
Aleksander Korovin

Reputation: 349

Works, only if i REDRAW EVERYTIME AFTER ADDING EACH POINT. so bad solution, so bad.

just put true in parameter after Point object

chartObject.chart.series[z].addPoint(Point, true, false);

Upvotes: 0

Related Questions