I could not find an answer in the bunch of posts so decided to ask for help. My javascript code is autorun after website has opened. Some calculation are done on server and got back json object. I use json data to make chart:
var xdata1 = JSON.parse([xListaCzasA.val()]);
var ydata1 = JSON.parse([yListaCisnienieA.val()]);
var data1 = [
{x:xdata1, y:ydata1},
];
var ctx = document.getElementById("wykres1").getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: xdata1,
datasets: [{
label: 'myTEST',
data: ydata1,
backgroundColor: 'rgba(255, 99, 132, 0.2)',
}]
},
Graph shows nice so works correct. After some click button I do a second calculation and again got a new json object. Calculations works becouse I see the results in the textboxes.However, my graph is not refreshing. I has created a piece of code below for update the graph. However, it not works:
function dane() {
myChart.config.data.labels = xdata1;
myChart.config.data.datasets.data = ydata1;
myChart.update();
}
Any ideas? I has try many cofig of the code from websites but it not works.
The datasets are an array of of datasets. So you can just target data on datasets. You need to select the correct one first. Asuming you only have 1 dataset that can be done like so:
function dane() {
myChart.config.data.labels = xdata1;
myChart.config.data.datasets[0].data = ydata1;
myChart.update();
}