score:0
i think you are stuck at to create piedata for the chart form json. here is the solution:
your json string:
$json = '[{"clinic_name":"clinic 1","total_checked_up":"4"},{"clinic_name":"clinic 2","total_checked_up":"0"},{"clinic_name":"clinic 3","total_checked_up":"0"},{"clinic_name":"clinic 4","total_checked_up":"0"}]';
first convert it to array:
$array = json_decode($json);
declare the empty variable:
$string_array = '';
loop threw the array:
foreach($array as $single_array){
$string_array[] = array(
'value'=>$single_array->total_checked_up,
'color'=>'#f56954',
'highlight'=>'#f56954',
'label'=>$single_array->clinic_name
);
}
convert the array into json again to get your desired piedata:
var piedata = json_encode($string_array);
this is how your piedata data look like.
[
{
"value": "4",
"color": "#f56954",
"highlight": "#f56954",
"label": "clinic 1"
},
{
"value": "0",
"color": "#f56954",
"highlight": "#f56954",
"label": "clinic 2"
},
{
"value": "0",
"color": "#f56954",
"highlight": "#f56954",
"label": "clinic 3"
},
{
"value": "0",
"color": "#f56954",
"highlight": "#f56954",
"label": "clinic 4"
}
]
Source: stackoverflow.com
Related Query
- how to populate my chartjs piechart dynamically
- how to change Y axis value dynamically based on user input in Chartjs for Line chart?
- How to dynamically set ChartJs line chart width based on dataset size?
- How to add ChartJS code in Html2Pdf to view image
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- How to generate color code dynamically by swapping 2 characters within a string using PHP
- How to add new data point and remove leftmost data point dynamically in Chartjs
- using ajax populate dynamic piechart from chartjs
- Chartjs Radar chart - How to dynamically highlight one of the gridlines at a specific point
- chartjs how to update dynamically data from database(Chartjs cant get the data)
- How to populate multiple charts dynamically with Chart.js in Typescript
- How to get ChartJs object from dynamically created chart
- How to dynamically update Chartjs legend label colors?
- How to run Chart.js samples using source code
- Dynamically update values of a chartjs chart
- How to set ChartJS Y axis title?
- Chartjs random colors for each part of pie chart with data dynamically from database
- How to disable chartjs legendclick
- how to change size of point in ChartJS
- How to disable a tooltip for a specific dataset in ChartJS
- How to modify chartjs tooltip so i can add customized strings in tooltips
- How to modify bar width in Chartjs 2 bar charts
- ChartJs 2.0 How do I obtain point information being clicked upon?
- how to plot multiple time series in chartjs where each time series has different times
- How to push datasets dynamically for chart.js (bar chart)?
- How to make integer scale in Chartjs
- How get sum of total values in stackedBar ChartJs
- chartjs : how to set custom scale in bar chart
- Dynamically update the options of a chart in chartjs using Javascript
- Chartjs linechart with only one point - how to center
More Query from same tag
- ChartJs 2 How to remove numbers from the doughnut chart on loading
- Importing data from Model into a View gives me an error I cannot solve
- How to make a chart with an associative array with chart.js?
- Chartjs: Make some ticks (Sunday, Saturday) red
- Is there a max width of canvas Chart.js can draw charts within?
- Retrieving daily & monthly totals from MySQL for use in a chart
- How to convert UNIX timestamp to date using chart.js?
- Chart.js show tooltips on page load
- chartJS Horizontal Bar - Hide Stacked Bars But Still Show In Tooltip
- Chart.js bar chart mouse hovering highlights all the datasets instead of just the selected one
- ChartJS 2 lines each with different fill gradients
- Graph is not displayed
- Angular-Chart-JS - Line chart with different fill colors according to points' range
- Make labels of ChartJS radar in a few rows
- ChartJS : How to display two "y axis" scales on a chart
- How to draw a horizontal line over bar columns in Chart.js that's started from X axis?
- Comparison between d3.js and chart.js (only for charts)
- Grab array from div text to plot with ChartJS
- Reactjs- Bar Graph-chartjs- Data not coming in individual blocks
- chartJS or/and php print_r not working together
- Adding a label to a doughnut chart in Chart.js shows all values in each chart
- Chart.js stacked bar chart iterate over datasets
- Count up values in Chart JS
- Is there any way to show tooltip by default (without hover pie chart) on chartjs
- Chartjs and dynamic data arrays
- Using JSON file data in Chart.js
- Why isn't my X axes on my bar chart starting from zero?
- Modify the labels in chart.js when I update the chart
- Chart.js x-axes not working?
- ChartJs x-axis label to be in dateTime format issue: DD-MMM-YYYY, but displayed as MMM-YYYY-DD