Skythrust
Member
- Jul 9, 2019
- 133
- 7
Goodmorning,
I was wondering how I can use JSON values as variables for a chart.
I've got DateTime which should be the xValues, and I got Kh as my data, Whatever I tried, my chart is not correctly filled with his information.
JSON Output; [{"Kh":"7.8","DateTime":"2022-04-06,"},{"Kh":"9.4","DateTime":"2022-03-03,"},{"Kh":"9.4","DateTime":"2022-02-20,"},{"Kh":"11.5","DateTime":"2022-01-31,"},{"Kh":"8.5","DateTime":"2022-01-14,"},{"Kh":"8.3","DateTime":"2022-01-03,"},{"Kh":"8.8","DateTime":"2021-12-30,"},{"Kh":"7.3","DateTime":"2021-12-27,"},{"Kh":"7.7","DateTime":"2021-12-25,"},{"Kh":"7.4","DateTime":"2021-12-23,"}]
Thanks in advance!
I was wondering how I can use JSON values as variables for a chart.
I've got DateTime which should be the xValues, and I got Kh as my data, Whatever I tried, my chart is not correctly filled with his information.
JSON Output; [{"Kh":"7.8","DateTime":"2022-04-06,"},{"Kh":"9.4","DateTime":"2022-03-03,"},{"Kh":"9.4","DateTime":"2022-02-20,"},{"Kh":"11.5","DateTime":"2022-01-31,"},{"Kh":"8.5","DateTime":"2022-01-14,"},{"Kh":"8.3","DateTime":"2022-01-03,"},{"Kh":"8.8","DateTime":"2021-12-30,"},{"Kh":"7.3","DateTime":"2021-12-27,"},{"Kh":"7.7","DateTime":"2021-12-25,"},{"Kh":"7.4","DateTime":"2021-12-23,"}]
JavaScript:
<!DOCTYPE html>
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<body>
<canvas id="myChart" style="width:100%;max-width:600px"></canvas>
<script>
var xValues = [100,200,300,400,500,600,700,800,900,1000];
new Chart("myChart", {
type: "line",
data: {
labels: xValues,
datasets: [{
data: [300,700,2000,5000,6000,4000,2000,1000,200,100],
borderColor: "blue",
fill: false
}]
},
options: {
legend: {display: false}
}
});
</script>
Thanks in advance!