Incorrect rendering of values
Hi,
I've come across an issue where the data renders incorrectly on the chart.
The issue
I have a temperature chart with 3 lines: the minimum temperature for the previous period, the maximum temperature and the current temperature.
For some reason, the minimum temperature sometimes renders higher than the current and even the max. temperature on the chart (see screenshot), even though the values in the input are correct and are correctly shown in the live region of the legend.
Code example
JSFiddle
https://jsfiddle.net/e249ns3a/
Code
const timestamps = [ 1675810950, 1675811010, 1675811611, 1675812211, 1675812811, 1675813412, 1675814013, 1675814614, 1675815215, 1675815815, 1675816416, 1675817017, 1675817617, 1675818218, 1675818819, 1675819420, 1675820021, 1675820622, 1675821223, 1675821823 ];
const tempCurrent = [ -1.9375, -1.9375, -2.1875, -2.0625, -2.25, -2.25, -2.1875, -2.25, -2.375, -2.5, -2.3125, -2.375, -2.5625, -2.5, -2.5625, -2.4375, -2.5, -2.6875, -2.5625, -2.8125 ];
const tempMin = [ -1.9375, -1.9375, -2.1875, -2.1875, -2.25, -2.3125, -2.375, -2.3125, -2.375, -2.5625, -2.5625, -2.375, -2.5625, -2.625, -2.625, -2.625, -2.5625, -2.6875, -2.8125, -2.8125 ];
const tempMax = [ -1.5625, -1.5625, -1.9375, -1.875, -2.0625, -2.1875, -2.1875, -2.1875, -2.1875, -2.375, -2.3125, -2.1875, -2.3125, -2.4375, -2.4375, -2.4375, -2.4375, -2.5625, -2.5625, -2.5 ];
const uplot = new uPlot(
{
width: 700,
height: 400,
scales: {
'temperature_celsius': {
auto: true
}
},
series: [
{
label: 'Date & time'
},
{
label: 'Current temperature (°C)',
scale: 'temperature_celcius',
width: 1,
stroke: 'rgba(26, 57, 39, 1)'
},
{
label: 'Min. temperature (°C)',
scale: 'temperature_celsius',
width: 1,
stroke: 'rgba(0, 0, 255, 0.50)',
},
{
label: 'Max. temperature (°C)',
scale: 'temperature_celcius',
width: 1,
stroke: 'rgba(255, 0, 0, 0.50)',
}
],
axes: [
{},
{
scale: 'temperature_celcius',
label: 'Temperature (°C)',
values: (self, ticks) => ticks.map(rawValue => `${rawValue} °C`)
}
]
},
[
timestamps,
tempCurrent,
tempMin,
tempMax,
],
document.getElementById('chart')
);
Findings
I'll update this whenever I find new information.
- When I comment out the
scaleproperty for each series, the rendering seems to be correct.
you have two different spellings of the scale, so you have two different scales :)
temperature_celsius vs
temperature_celcius
if you only need a single scale, you should just omit it, and it will default to y/auto scale internally for all scales/series/axes.
let opts = {
width: 700,
height: 400,
series: [
{
label: "Date & time",
},
{
label: "Current temperature (°C)",
stroke: "rgba(26, 57, 39, 1)",
},
{
label: "Min. temperature (°C)",
stroke: "rgba(0, 0, 255, 0.50)",
},
{
label: "Max. temperature (°C)",
stroke: "rgba(255, 0, 0, 0.50)",
},
],
axes: [
{},
{
label: "Temperature (°C)",
values: (self, ticks) => ticks.map((rawValue) => `${rawValue} °C`),
},
],
};
@leeoniya 🤦 My apologies for the waste of time