In another thread it is suggested to use https://quickchart.io/ for the generation of graphs and I think it can be a solution to my problem of graphing the price/hour data of the PVPC of Spain.
I would need to assemble the chart chain with the data separated and declared as variables:
type
data
labels
datasets
labels
backgroundColor
borderColor
data (the prices of the table obtained from the api esios PVPC)
Just like I do with the url, height and width.
In addition, I would need to be able to use the url that is obtained in the visualization, to be able to see the png that it generates.
Thank you
You can use a JS chart library instead of a web service for this. See this example: https://forum.logicmachine.net/showthread.php?tid=3789
The data that you want to display can be saved into storage and loaded via .lp file.
Hi, thanks for the alternative. I've been looking at the suggested thread and I don't quite understand how it works. I would need a more detailed example.
I understand that using JS would be better, but how would it be done as I propose?
Thank you
Greeting
What does you user.lp return? It must be a valid JSON array with up to 24 numbers.
I've modified the example to handle resizing when plan changes. It fixed the issue when chart is not rendered correctly on a plan that is not visible when rendering happens.
Code:
$(function() {
$('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chartist/0.11.4/chartist.min.css" type="text/css">').appendTo('head');
$.getScript('https://cdnjs.cloudflare.com/ajax/libs/chartist/0.11.4/chartist.min.js', function() {
var el = $('<div></div>').css({
position: 'absolute',
width: '600px',
height: '300px',
left: '10px',
top: '50px',
zIndex: 999
}).appendTo('#plan-8');
$.getJSON('/user/data.lp', function(data) {
var labels = [];
for (var i = 0; i < 24; i++) {
var label = '';
if ((i % 3) == 0) {
label = i + ':00';
}
labels.push(label);
}
var chart = new Chartist.Line(
el.get(0),
{
labels: labels,
series: [ data ]
},
{
low: 0,
showArea: true
}
);
$('body').on('showplan', function() {
chart.resizeListener();
});
});
});
});
Hello
I'm going to collect the information to try to clarify myself.
1. I get the prices/hour of the PVPC with the esios api. The result is a Lua table that I store in storage with the name pvpc.
2. I create the data.lp file and save it to user
3. I copy the js script and change it to id4
Result
The graph is drawn but the data must be ordered from lowest hour 0 to highest hour 23, and since the price is different every hour, it cannot be that graph that increases.
I want a graph similar to the attached one, which is the one shown by esios.
14.09.2022, 16:24 (This post was last modified: 14.09.2022, 16:37 by JRP.)
Hello, I understand what you are saying, the table was stored out of order when putting the storage instruction, after ordering the table to obtain the minimum and maximum price. My mistake in putting the instruction at that point.
By putting the instruction at the right point, the table is saved in the ordered storage and the graph is displayed correctly.
Now I would like all times to be displayed and the :00 is not required as it is always the hour on the dot.
16.09.2022, 08:41 (This post was last modified: 18.09.2022, 18:52 by JRP.)
thanks i will try it.
How can I divide all the values by 1000 so that they are displayed on the graph? And one last request, is it possible for the Y axis labels to show the actual price values of each point, instead of being a scale?
other question
Testing this method on a wiser for KNX HW v2.0 with firmware 2.61, the graph is not drawn correctly.
I attach a screenshot.
I tried all kinds of positions and sizes and it never showed beyond hour 19. The data in the storage is correct and the Json with the data in the data.lp file is fine. And until hour 19 the graph corresponds.
for (var i = 0; i < data.length; i++) {
data[ i ] = data[ i ] / 1000;
}
var chart = ...
This chart library does not work correctly when plan scaling is enabled. See if replacing the URL from "https://cdnjs.cloudflare.com/ajax/libs/chartist/0.11.4/chartist.min.js" to "https://dl.openrb.com/misc/chartist.js" makes it work correctly.
Default Visualization settings have scaling enabled. So unless your visualization plan size is the same as the screen size it will be scaled.
Since the library doesn't adjust to scaling by default you will get something this:
With the fixed version it works correctly: