This means that your data is not a plain array of numbers. If each array item is an object containing value field then the data conversion should be like this:
Code:
for (var i = 0; i < data.length; i++) {
data[ i ] = data[ i ].value / 1000;
}
Now I would like to play a bit with the aspect of the graph.
For example, changing the background color, leaving only the line of data points and removing the lower red area of the curve, the color of the labels, etc.
Hello
I've tested it on my test Wiser and it works perfectly, thanks.
For now I can't test it on the client's Wiser and Umotion, what worries me is that Umotion being Javascript won't be able to execute it either.
Alternative in Lua?
Greeting
This .lp example will generate the chart. Modify it to use storage values instead of random values. Upload it as chart.lp, then use image element with remote source url set to /user/chart.lp
Code:
<?
math.randomseed(os.time())
local data = {}
for i = 1, 24 do
data[ i ] = {
value = math.random(100, 300)
}
end
local labels = {}
for i = 0, 23 do
local label = tostring(i)
if #label == 1 then
label = '0' .. label
end
labels[ #labels + 1 ] = label
end
for i, item in ipairs(data) do
data[ i ] = item.value / 1000
end
local width = 600
local height = 400
local params = {
type = 'line',
data = {
labels = labels,
datasets = {
{
label = 'Prices',
backgroundColor = 'rgb(255, 99, 132)',
borderColor = 'rgb(255, 99, 132)',
data = data,
fill = false,
}
}
},
options = {
title = {
display = true,
text = 'Title',
}
}
}
local cdata = ngx.escape_uri(require('json').encode(params))
local url = 'https://quickchart.io/chart?w=' .. width .. '&h=' .. height .. '&c=' .. cdata
I'm using bar chart, would it be possible to get different bars in different colors when bars are over and under limits? Lets say under 7 is blue, 7-8 is green, 8-9 is yellow, over 9 is red etc.