score:0
from what i see in your function for rendering the chart you are passing the data for each dataset as a parameter. instead, modify your backend to fetch the data for all datasets to look like:
{
"loans": [2],
"payments": [3]
...
}
i've added a function in my js to set the data accordingly for my chart:
function getchartdata(data) {
let chartdata = {
labels: ["# of records"], // on your case this is enough
datasets: []
};
object.keys(data).foreach(function(label, index) {
chartdata.datasets.push({
label: label,
data: object.values(data[label]),
bordercolor: colors[index]
});
});
return chartdata;
}
colors
is just an array with hex color strings, as many as you like. i've created a function to generate a random color if the datasets become too many.
then when i create my chart i simply pass the result of that function to the data
of the chart.
you'll have modify this depending on your backend. check this fiddle.
Source: stackoverflow.com
Related Query
- How to generate dynamic bar chart in laravel using chart.js
- How to create stacked bar chart using react-chartjs-2?
- How to use set the color for each bar in a bar chart using chartjs?
- How to display chart using Chartjs with JSON data in Laravel
- How to draw multiple color bar in a bar chart using chart.js
- Using two JSON objects to make Chart.JS Bar Chart Dynamic in Typescript / Angular
- How to generate color code dynamically by swapping 2 characters within a string using PHP
- How to highlight single bar in bar chart using Chartjs
- How to make dynamic chart using Vue component with chart-js
- How to make dynamic chart js using JSON in Codeigniter?
- Generate bar chart using chart.js and associative array
- How to draw multiple color bars in a bar chart along a Horizontal Line using chart.js
- How to show symbols after the label and before the numeric value using chart.js Bar chart in Angular
- How to set Solid label in bar chart using Chart JS
- how to insert dynamic data from sql into chartjs stacked bar chart javascript
- How to show bar chart labels clearly using ChartJS?
- How to custom index label on each bar chart using chartjs?
- Is it possible to generate multiple chart in Laravel using chartjs ? If possible please give the solution
- How to configure Chartjs Bar Stacked Chart in Laravel 8
- How Can I Get An Instance of a ChartJS Bar Chart Using Angular
- How to display grouped bar chart using chart.js?
- How to generate multi bar chart in Chart.js with php & sql
- How to run Chart.js samples using source code
- How to generate bubble chart (Chart.js) using data from database FILTERED by user in Django?
- how to modify horizontal bar chart using chart js
- how to show data value on bar chart body rather than using tooltip?
- How to create an animate-on-update Stacked Bar chart using Chart.js(or Chartist)?
- How to add label square to Bar Chart using Chart.js
- How to convert a bar chart into a triangle shaped chart using Chart JS?
- How to add vertical line in bar chart using chartJs and ng2-charts?
More Query from same tag
- how to get React chartjs to resize back down with window
- Need to customize graph behaviour
- Angular 9: Chart.js: Monochromatic(Single color with shades) doughnut chart
- ng2-charts doughnut chart with different data per series
- Chart js, Canvas is null polymer project
- Use Chartjs with reactjs
- Zoom Function For Chart.js
- Chart.js: Set different options to datasets
- Datalabels plugin throws error when using scriptable option
- Chartjs 2.x - Dataset color changing when redrawing chart
- Can't get Chart.js to run in a Vue.js component
- Creating multiple charts and selecting them later
- Chart JS title passed from Django - issue with apostrophe '
- How to remove the inside-border from doughnut chart? Chart.js
- chartjs-plugin-zoom not working on offline environment javascript .js
- I can't change the color of the grids in Chart.js
- Customization of Data Labels in doughnut chart ng2-charts
- Chartjs with streaming plugin: update y-range
- Chartjs backgroundColor for line chart does not appear in Vue app
- AmCharts: Clustered bar chart with sub-categories
- Determining which chart the user has clicked on
- How to assign an array to data of charts.js's counts
- Chart.js - Horizontal line on Bar chart interferes with tooltip
- Chart.js setting maximum bar size of bar chart
- How to remove the extra Y axis from a bar chart in chart.js
- Chart.js don't work when I open my app as a stand alone app in Chrome
- Only first value added gets displayed in ng2-chart linechart
- Chart.js and Firebase Ionic App Angular 4
- Change color of Polar Area datasets in Angular
- In which stage of the program do I remove my legend labels in charts.js?