03.10.2022, 13:10
Try this:
Code:
$(function() {
$.getJSON('/user/data.lp', function(data) {
var labels = [];
for (var i = 0; i < 24; i++) {
var label = i.toString();
if (label.length == 1) {
label = '0' + label;
}
labels.push(label);
}
for (var i = 0; i < data.length; i++) {
data[ i ] = data[ i ].value / 1000;
}
var width = 600;
var height = 400;
var 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',
},
},
};
var cdata = encodeURIComponent(JSON.stringify(params));
var src = 'https://quickchart.io/chart?w=' + width + '&h=' + height + '&c=' + cdata;
$('<img>').css({
position: 'absolute',
width: width + 'px',
height: height + 'px',
left: '10px',
top: '50px',
zIndex: 999
}).appendTo('#plan-8').attr('src', src);
});
});