Quadratic equation plot with ui_chart - Dashboard 2.0

Hello there,

New to Node Red and I'm trying to plot quadratic equation using function below:

// Quadratic coefficients
const a = 1;
const b = -2;
const c = 1;

// Generate data points
const points = [];
for (let x = -10; x <= 10; x += 0.5) {
    const y = a * x * x + b * x + c;
    points.push({ x: x, y: y });
}

// Format for ui_chart (Dashboard 2.0)
msg.payload = [
    {
        label: "y = ax² + bx + c",
        data: points
    }
];
return msg;

problem with plotting with ui_chart. it doesn't accept data as array but it can only read data in object pair of { x: x, y: y } with only plot one point. how can I plot whole graphic for x =-10 to 10 using ui_chart?

Sure it does. Just put your data in the shape expected as per several of the documented examples in the online documentation.

Try this (untested)

// Quadratic coefficients
const a = 1;
const b = -2;
const c = 1;

// Generate data points
const points = [];
for (let x = -10; x <= 10; x += 0.5) {
    const y = a * x * x + b * x + c;
    points.push({ x: x, y: y });
}

msg.payload = points
return msg;

Be sure to set the label in the chart edit panel (or use dynamic props as described in docs)

also, set the x to come from key.x and y to come from key.y

Great, this is exactly what I needed.