score:0
Accepted answer
i have successfully build a bar chart. here is the code. you can run in the snippet but make sure your http://localhost:1111/barangall
provides the data without any cross-origin issue.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.8.0/chart.bundle.js"></script>
<canvas id="mychart" width="400" height="400"></canvas>
<script>
var ctx = document.getelementbyid('mychart').getcontext('2d');
var dataset = {
type: 'bar',
data: {
labels: [],
datasets: [{
label: 'data barang',
backgroundcolor: 'rgba(200, 200, 200, 0.75)',
bordercolor: 'rgba(200, 200, 200, 0.75)',
hoverbackgroundcolor: 'rgba(200, 200, 200, 1)',
hoverbordercolor: 'rgba(200, 200, 200, 1)',
data: []
}]
},
options: {
scales: {
yaxes: [{
ticks: {
beginatzero: true
}
}]
}
}
}
var getdata = function(chartdata) {
$.ajax({
url: 'https://api.myjson.com/bins/ovkgh',//http://localhost:1111/barangall
success: function(data) {
//console.log(data);
data.foreach((el, i) => {
chartdata.data.labels.push(el.nama);
chartdata.data.datasets[0].data.push(el.stok_awal);
});
var mychart = new chart(ctx, chartdata);
}
});
};
getdata(dataset);
</script>
Source: stackoverflow.com
Related Query
- How to show percentage (%) using chartjs-plugin-labels ( Pie chart ) in angular 2/8
- How to show slice value inside of slice in pie chart using chart.js
- How to plot chart from external JSON and format X-AXIS to show time using Chart.JS?
- how to show speedometer on Doughnut chart in chart.js using reactjs
- How to show symbols after the label and before the numeric value using chart.js Bar chart in Angular
- How can I show "No Data" message in Pie Chart when there is no data using VueJS?
- How to show bar chart labels clearly using ChartJS?
- how to show chart using chart js
- How to run Chart.js samples using source code
- how to show data value on bar chart body rather than using tooltip?
- How to add text inside the doughnut chart using Chart.js?
- How to add an on click event to my Line chart using Chart.js
- Chart.js how to show cursor pointer for labels & legends in line chart
- How to save Chart JS charts as image without black background using blobs and filesaver?
- How to Draw Gantt chart using chart js or other libraries
- How to add text in centre of the doughnut chart using Chart.js?
- How to create stacked bar chart using react-chartjs-2?
- chart js tooltip how to control the data that show
- How to show percentage (%) in chart js
- how to show multiple values in point hover using chart.js
- How to access labels array using chart plugin (Chart.pluginService.register) in Chartjs 2.x?
- Chartjs - show elements in all datasets on hover using bar chart
- How to display the labels in doughnut chart using ng2 charts?
- How to create single value Doughnut or Pie chart using Chart.js?
- PrimeNg bar chart how to show a label for the y-axis
- Show labels on each sector to polar chart using angular js chart
- How to show data values in top of bar chart and line chart in chart.js 3
- Chart.js - How to show loading animation before plotting chart
- How to make a chart scroll horizontally (when using Chart.js)
- Show point values in Radar Chart using chart.js
More Query from same tag
- Chartjs average line over bars
- How to Increase the label font size and decrease the size of my pie using chart.js?
- Line Chart: background of RangeSlider
- How to align ChartJS bars to the left?
- Why isn't my Angular 4 ChartJS component rendering?
- Datetime picker in Chart.js
- Chart.js showing x-axis ticks even though set to false
- Resizing vue-chartjs height while keeping it responsive
- How to set Solid label in bar chart using Chart JS
- Chartjs: update the min and maximum of the yaxes ticks on a click
- How to change bar color acording to label value in chartjs
- Add new line in es6 inside a doughnut chart
- Chart, X and Y-Axis labels are blurred in horizontal bar chart using chart.js
- AutoSkip: False not working on time xAxes labels
- Using Chart.js with Gatsby markdown
- AmCharts: Clustered bar chart with sub-categories
- Beginner using chart.js: having trouble display state full of data into a column chart using variables
- Change 'points' on a line chart to donuts using Chart.js
- How to dynamically set backgroundColor and borderColor barchart unsing Chart.js
- Charts not rendering properly in Angular
- how can i show labels and value in both on bar chart
- Chart.js – how to remove data entries from the tooltip?
- Range at the end of the line chart
- How to distribute the y-ticks proportionally in Chart.js in Flask app?
- Embed <canvas> tag in Laravel Markdown?
- Data is not display in correct order after update
- Why is this Chart.js graph not showing the right colors?
- Chart JS: is possible mix Scatter and bar chart in Chart JS?
- Updating Chartjs dataset in Ionic
- how to make doughnut chart portions, buttons