I'm trying to display my data in pie/donut chart format.. Easiest i found over the internet is the simple google chart. However, it's not as simple as it looks.. I still stuck at passing the data to generate the chart. Really appreciate your help/suggestions/solutions for noob like me.. Thanks in advance
I already have the data in a table format and now im trying to change the display into pie/donut chart.
This is my code to display the data.. (in table format)
<table class="table table-striped table-bordered table-hover table-checkable dataTable no-footer" cellspacing="0" rules="all" border="1" style="border-collapse:collapse; margin-bottom: 0;">
<tr>
<td>Female</td>
<td class="text-center"><asp:Literal runat="server" ID="tFemaleOccupied"></asp:Literal></td>
</tr>
<tr>
<td>Mix</td>
<td class="text-center"><asp:Literal runat="server" ID="tMixOccupied"></asp:Literal></td>
</tr>
<tr>
<td>Queen</td>
<td class="text-center"><asp:Literal runat="server" ID="tQueenOccupied"></asp:Literal></td>
</tr>
<tr>
<td>Suite</td>
<td class="text-center"><asp:Literal runat="server" ID="tSuiteOccupied"></asp:Literal></td>
</tr>
</table>
I plan to change to this
<table class="table table-striped table-bordered table-hover table-checkable dataTable no-footer" cellspacing="0" rules="all" border="1" style="border-collapse:collapse; margin-bottom: 0;">
<tr>
<td>
<div id="piechart"></div>
</td>
</tr>
</table>
This is script for "piechart" using google chart
<asp:Content ID="Content4" ContentPlaceHolderID="cphPageScripts" runat="server">
<script src="/assets/pages/scripts/dashboard.min.js" type="text/javascript"></script>
<script type="text/javascript">
// Load google charts
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
// Draw the chart and set the chart values
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Room Type', 'No of Room'],
['Female', 'FemaleOccupied'],
['Mix', 'MixOccupied'],
['Queen', 'QueenOccupied'],
['Suite', 'SuiteOccupied']
]);
// Optional; add a title and set the width and height of the chart
var options = {'title':'Room Occupancy', 'width':'50%', 'height':'50%'};
// Display the chart inside the <div> element with id="piechart"
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
How to pass value "tFemaleOccupied" to 'FemaleOccupied' in data array?
var x = <?= json_encode($data) ?>;. The other option is to use Ajax.