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
- Vuejs, how to build an object?
- Accessing a slice of a react-chartjs Pie chart
- Outputting multiple SQL queries in chart.js
- Chartjs - line chart display with addData() is bugged?
- Chart.js 2.0 - Tooltip is showing incomplete data on hover
- ChartJS - Adding legend title into tooltip title
- how to fix this error Array to string conversion in laravel and chartjs?
- How to iterate over array elements inside objects in javascript
- ChartJS Radar Chart radar lines color?
- chart.js dynamically adjust gap between vertical bars
- Convert SQLite PHP array into Javascript array?
- Sending 2 fetched result into AJAX
- Chart.js different time datasets
- Can Chart.js Horizontal bar work with time series data?
- Cant To CHange Chart.js Legend
- When using chart.js to draw a line chart, if the peak is between two x values instead of "at a x value"
- Remove empty spaces created by null values in Chart.js
- Is it possible to create context menu with chart.js?
- Chart.js v2.6: Add arrows to pie chart output values
- How can I display `Null` value data on Y Axis using the Primitive dataset format in Chart.js V3.7.0?
- Chart.JS multiple plugins do not operate
- Is it possible to add individual labels to Chart.JS bars?
- ChartJS V3 Radar chart Label Font Size
- Jinja throughs "SyntaxError: expected property name, got '%' " error
- Unable to Draw Chart using ChartJS
- chart.js - problems with axes options - what am I doing wrong?
- Automatic resize of chart - AngularChartJS
- Chart.js HiLo chart example
- Line chart is not being displayed in Chart.js
- Angular charts is not displayed