score:0
Accepted answer
var ctx = document.getElementById("myChart").getContext('2d');
var myData = [1, 3, 5, 7, 10, 15];
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: myData,
backgroundColor: [
'rgba(255, 99, 132, 0.5)',
'rgba(54, 162, 235, 0.5)',
'rgba(255, 206, 86, 0.5)',
'rgba(75, 192, 192, 0.5)',
'rgba(153, 102, 255, 0.5)',
'rgba(255, 159, 64, 0.5)'
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
function updateData(chart, labels, mydata) {
//if(labels) chart.data.labels = labels;
//chart.data.datasets.forEach((dataset) => {
// dataset.data[0]++; // Or you can cheng data like this
//});
chart.update();
}
setInterval(function(){
myData[0]++;
updateData(myChart,null,myData);
},1000);
<div style="width: 500px; height: 500px">
<canvas id="myChart" width="400" height="400" style="width: 400px !important"></canvas>
</div>
<script src="http://www.chartjs.org/dist/2.7.2/Chart.bundle.js"> </script>
Source: stackoverflow.com
Related Articles
- how to dynamicly change the json data in chartjs
- Displaying JSON data in Chartjs
- Chartjs Data via json request not populating
- How to display chart using Chartjs with JSON data in Laravel
- How to create a custom tooltip for chartJS graph with data in JSON array in JavaScript?
- Passing JSON data from PHP array into ChartJS
- Dynamically pass the JSON data in chartjs
- ChartJS - How to change color of some data points in graph
- Read google sheet json data into chartjs
- Change data onclick with ChartJS
- passing json data to chartjs
- load external json data file in to chartjs in the angular component
- Rendering Rails json data in chartjs
- Chartjs in Vue integrate parsed Json Data
- ChartJS have xAxes labels match data source
- JSON cyclic object value when posting data in ChartJS
- How to use JSON data as chartjs data?
- Transform JSON data for ChartJS
- ionic display chartjs data from json http request
- Json data visualization in Javascript with chartjs
- Calling data from outside of Chartjs code
- VueJS + Chartjs - Chart only renders after code change
- Displaying JSON data with Chartjs
- ChartJS Tooltip - Change Data Format Displayed
- How can I reload data from chartjs after JSON file was modified in a HTTP POST
- Create a chartjs pie chart using json data
- chartjs - json data for scatter graph, issue with date
- How do I add JSON Data into ChartJS
- How could i change my JSON structure into chartJS barchart JSON structure?
- Using ChartJS and JSON to render charts; Appending JSON Data to javascript yields an empty object in console.log
- Chartjs, scatter with For-Loop
- Chart JS Re-Animate chart with onclick
- Using chart js options with react-chartjs-2 and typescript
- Having legends inside the Chart.js canvas
- How to convert Json to Array In javascript for chart.js
- How to add space Between Columns in Bar chartjs and remove the space in the end
- Adding options to vue-chartjs seems not working
- How to create a charjs bar graph with many bars?
- How to skip x Axes labels in ChartJS
- Drawing line chart in chart.js with json data
- Chart JS pass in custom data for points
- chartjs-vue charts are empty
- How to offset axes in a scatter plot?
- Why is borderColor function in chartjs running multiple times, and how to reduce it?
- Chart.js Box Annotations Fill Entire Chart
- How to properly use the chartjs datalabels plugin
- Doughnut chart - interaction with specific segment of a chart
- Cannot find module 'chart.js'
- chart.js change size of label of radar chart
- chart.js addData breaks function v1.0.2