score:8
chart.data.datasets
is an array of datasets, not a single dataset. datasets
does not have its own data
and label
attributes. Rather, each individual dataset
in the array has its own data
and label
attributes. You therefore cannot do datasets.data
or dataset.label
.
If you want to update the data
or label
variable of a specific dataset, you need to select that object from the array. To select the first dataset, simply use datasets[0]
:
chart.data.datasets[0].data = [amazon, google, facebook, twitter];
chart.data.datasets[0].label = label;
If you want to update all datasets, use a forEach
loop to iterate through the array:
chart.data.datasets.forEach((dataset) => {
dataset.data = [amazon, google, facebook, twitter];
dataset.label = label;
});
Two more points:
One other possible problem is that the names
variable is not initialized anywhere, though it could be that you just didn't include that part of the code in your question.
Also, why do you have the following three lines of code, if you just reassign all the values in the next three lines of code?
chart.data.datasets.data = [];
chart.data.labels = [];
chart.data.datasets.label = null;
Source: stackoverflow.com
Related Query
- Chart.js chart.update() method is not doing anything
- Chart.js update function (chart,labels,data) will not update the chart
- Annotation events not update the chart
- Chartjs destroy method not affecting the chart
- Angular-Charts bar chart does not update when I change the data, series, labels
- Chart.js: chart does not update
- Primeng line chart not updating automatically,only update on window refresh
- ChartJS, updating chart type does not update xAxis properly
- Chart.js chart in vue.js component does not update
- Can not update bar chart values in Chart.js 2.0.0 alpha3
- I am using chart js to draw a chart. I did everything right but i don't know why the x axis and y axis label is not comming in chart. code below
- My Chartjs is not updating after setstate full code attached Reactjs Update
- how to not repeat code while creating multiple charts in chart js
- Dynamically update values of a chartjs chart
- ReferenceError: Chart is not defined - chartjs
- Chart.js: bar chart first bar and last bar not displaying in full
- Dynamically update the options of a chart in chartjs using Javascript
- TimeSeries scale in ChartJS 3.0.2. brings error "This method is not implemented: either no adapter can be found or an incomplete integration was ..."
- Chart.js responsive option - Chart not filling container
- show label in tooltip but not in x axis for chartjs line chart
- Angular-Chart not rendering anything
- Html chart does not fit a small Android WebView
- Chart.js ng2-charts colors in pie chart not showing
- Chart.JS Mixed Chart - Bars Not Showing
- Chart looks only grey, does not show the color - Chartjs,discordjs
- Angular-chart.js - Make line chart does not curve
- angular-chartjs line chart TypeError: t.merge is not a function
- Chart.js line chart is not displaying
- Chart.js: width and height of a pie chart not respected
- Uncaught TypeError: Chart is not a constructor when using Chart.js
More Query from same tag
- Mapping data (from getJSON response) in Chart.js
- ChartJs: Loading fresh data to Chart
- What happened to generateLegend() in chartjs 3.0?
- ChartJS vector maps
- Convert a JSON file to an array in javascript to visualize the data in ChartsJS
- How do you add custom text to tooltips in charts.js
- Make months on x-axis clickable on chart.js line chart
- How to use Chart.js with Typescript without getting assignable errors?
- when showing large amount of data graph not displaying from middle
- Chart.js - Responsiveness not correctly working on device orientation change
- ChartJS - Line Chart with different size datasets
- Cannot find centroid of path
- Can "Bar" be placed center of vertical grid line in Chart.js?
- code works fine on jsfiddle but one function is not working on website
- How Can I Change the Y-axis labels to be shown as strings other than number in Chart.js?
- Why is each character displayed on a new line/row?
- Chart.js. Values in a big range. The smallest values are not available
- return array from ajax
- Can chart.js display text associated with each point on a line chart that is permanently visible?
- How to disable a custom tooltip for a dataset in Chart.js line chart?
- Chartjs Options are ignored
- Adding new data to empty Chart.js chart does not render new data correctly
- Overlap chart datasets with different view types in Chart.js
- Construct a bar chart using chart.js
- Chart.js show data in chronological order
- How can I modify category labels font size in Chart.JS V2?
- chartjs push array to label not working
- Using Chart.js with Gatsby markdown
- How to create dataset in chart.js dynamically using array?
- I cannot update my chart ( in react-chartjs-2 )