score:3
Accepted answer
in case you're still trying to get it to work, here is how i did it:
<script type="text/javascript">
$.ajax({
url:"getdata.php",
method:"get",
success:function(data) {
console.log(data);
var malenum =[1];
var femalenum =[2];
var ctx = document.getelementbyid("mychart");
var mychart = new chart(ctx, {
type: 'pie',
data: {
labels: ["male","female"],
datasets: [{
label: 'genders',
data: [malenum,femalenum],
backgroundcolor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)'
],
bordercolor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)'
],
borderwidth: 1
}]
},
});
},
error:function(data){
console.log(data);
}
});
</script>
Source: stackoverflow.com
Related Query
- Pie chart with Chart.js and mySQL
- Map with pie chart and label
- How do I make a pie chart showing number of people in an age group with JSON and ChartJS?
- pie chart in php with mysql data using chart.js
- Chartjs random colors for each part of pie chart with data dynamically from database
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- chartjs datalabels change font and color of text displaying inside pie chart
- Chart.js Mixed Bar and Line chart with different scales
- Problem for display a chart with Chart.js and Angular
- Show X axis on top and bottom in line chart rendered with Chart.js 2.4.0
- How to display data labels outside in pie chart with lines in ionic
- Chart.js: width and height of a pie chart not respected
- Can we draw a Line Chart with both solid and dotted line in it?
- Increase padding between legend and chart with react-chartjs-2
- Chart,js Pie Chart can the gap between a pie chart and the legend be adjusted
- Show "No Data" message for Pie chart with no data
- chart.js pie chart issue with display: none
- Use transparent stroke color with chartjs pie chart
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- React chart : prevent chart's canvas scaling with height and width
- Why would a ChartJS chart end up with width 0 and height 0?
- Configure Pie Chart Colors Using Chart.js and PHP
- Using chart js options with react-chartjs-2 and typescript
- Trying to load a chart with chart.js, through ajax and php
- ERROR TypeError: "this.canvas is undefined" | Problem with creating a chart with angular and chart.js
- Issue while plotting bar chart with custom x-axis with month and year in chart.js
- Grouped Bar Chart from mySQL database using ChartJS and PHP
- How to get chart from data points (arrays) with inconsistent time intervals and chart.js?
- Vue Chart.js Doughnut Chart with rounded and spaced arcs (vue3-chart-v2)
- Dynamic line chart with chart.js and PHP
More Query from same tag
- How can I export data from a csv file or excel file to a javascript object?
- Click every label onload ChartJS
- HTML tags enable in Default tooltip labels in chart.js
- Add chart using chart.js in codeigniter
- Chartjs display bug when pushing data to graph
- Is this graph possible using chart.js?
- Display values outside of pie chart in chartjs
- How to change font weight of footer in tooltips in Chart JS
- ChartJS -- How do I change scale color when I have to scales?
- Chart.js minimal width of Chart with scrollable overflow
- How to remove labels from ng2-chart(chart.js)
- Chart.js stacked bar chart text on top of the stacked bars
- how to show data label on barchart using chart.js in Angular10 project?
- add labels dynamically in Charts.js
- Using two JSON objects to make Chart.JS Bar Chart Dynamic in Typescript / Angular
- how to use require(chart.js) in codesandbox
- How do I present progress in an Angular bar chart?
- Count the duplicates in a string array using React JS
- customizing tooltip on chart.js bar chart
- Chart with Time axis only displaying first grid line and tick label (unitStepSize)
- Chart.js V2 line chart missing point
- How to create a custom tooltip for chartJS graph with data in JSON array in JavaScript?
- I dont know how to sum expenses based on category in sequelize
- Tooltip overriding the text in chart js
- JavaScript Chart.js - Custom data formatting to display on tooltip
- Y-Axis with different colors
- Change labels colors for radar chart js
- Chart.js Plugin Not Recognized as Options Property in Angular
- Chart.js - how to disable everything on hover
- How do I prevent the scale labels from being cut off in chartjs?