leeoniya / uPlot

📈 A small, fast chart for time series, lines, areas, ohlc & bars
MIT License
8.59k stars 373 forks source link

idxs is empty #959

Open Scheuraa007 opened 3 weeks ago

Scheuraa007 commented 3 weeks ago

Hello together, i have the following chart options.

{
        title: "Graph",
        width: 200,
        height: 110,
        cursor: {
            drag: {
                setScale:false,
                x: false,
                y: true,
            },
        },
        select: {
            show: false,
            height: 0,
            left: 0,
            top: 0,
            width: 0,
        },
        plugins: [touchZoomPlugin(), tooltipsPlugin(), clickPlugin(), mousePanPlugin()],
        scales: {
            x: {
                time: false,
            },
            y: {
                         auto: false, 
                min: yMin, // initial value
                                max: alertValue, // initial value
                range: () => {
                    return [ yMin,alertValue];
                },
            },
        },
        series: [
            {},
            {
                show: true,
                label: "ppm",
                stroke: "#007ab3",
                width: 2,
                points: {
                    show: false,
                },
            },
            {
                show: false,
                label: "speed",
                stroke: "orange",
                width: 2,
            },
            {
                show: false,
                label: "time",
                stroke: "green",
                width: 2,
            },
            {
                show: true,
                stroke: "#000000",
                width: 2,
                points: {
                    show: false,
                },
            },
            {
                show: true,
                stroke: "#15ff00",
                width: 2,
                points: {
                    show: false,
                },
            },
        ],
        axes: [
            {
                grid: {
                    show: false,
                },
                show: false,
            },
            {
                grid: { show: false },
            },
        ],
        legend: {
            show: false,
        },
        hooks: {
            drawSeries: [
                function alertSeries(u, si) {
                    drawLine(u, si, alertValue, "red");
                },
            ],
        },
    }

And i set the data to this chart with the following method:

const receivedData = this.data as RouteData;
this.activeRouteCoordinates[this.activeRouteCounter] = receivedData.coordinates[0];
this.activeDataPoints = [
    [...this.activeDataPoints[0], this.activeRouteCounter],
    [...this.activeDataPoints[1], receivedData.mainMeasurement[0]],
    [...this.activeDataPoints[2], receivedData.speed[0]],
    [...this.activeDataPoints[3], receivedData.time[0]],
    [...this.activeDataPoints[4], receivedData.secondMeasurement[0]],
    [...this.activeDataPoints[5], receivedData.thirdMeasurement[0]],
];
this.activeRouteCounter++;

const dataLength = this.activeDataPoints[0].length;
if (dataLength > 200) {
    this.chart.setSize({
        width: dataLength,
        height: getHeightForGraph(),
    });

    const newScrollWidth = getBrowserWidth();
    if (this.chartWidth < newScrollWidth && !this.autoscroll) {
        window.scrollBy({ top: 0, left: 5, behavior: "smooth" });
        this.chartWidth = newScrollWidth; // aktualisiere scrollWidth
    }
} else {
    this.chart.setSize({
        width: 200,
        height: getHeightForGraph(),
    });
}

if(IsZoomed === false)
{
        this.chart.setData(this.activeDataPoints);
        window.smtGraph.coords = this.activeRouteCoordinates;
}
    else
{
    this.chart.scales.y.range = () => [ Y_range[0],Y_range[1]];
    setYrange(false,Y_range[0],Y_range[1]);
}

This method is called about 3 times a second. When i check this.chart.data after the method all data is in it. But when i check the series the idxs of them are all an empty array. Can anybody help me why i have this problem?

Scheuraa007 commented 3 weeks ago

Seems like it is an 1.6.30 Bug. On Version 1.6.20 the same code worked