I am building an app that has a dashboard with a graphical representation of data. It's a template. I want the values to be dynamic on the chart, i.e. I want use php
to pass the values to the chart.
The problem is that values are set in a '.js' file. How can i pass values from the database to the file in order to display them?
Please help
this is my html
<!-- Chart Widget -->
<div class="widget">
<div class="widget-content border-bottom">
<span class="pull-right text-muted"><?php echo htmlentities(date("Y")); ?></span>
Last Year's Data
</div>
<div class="widget-content border-bottom themed-background-muted">
<!-- Flot Charts (initialized in js/pages/readyDashboard.js), for more examples you can check out http://www.flotcharts.org/ -->
<div id="chart-classic-dash" style="height: 393px;"></div>
</div>
<!--
<div class="widget-content widget-content-full">
<div class="row text-center">
<div class="col-xs-4 push-inner-top-bottom border-right">
<h3 class="widget-heading"><i class="gi gi-wallet text-dark push-bit"></i> <br><small>$ 41k</small></h3>
</div>
<div class="col-xs-4 push-inner-top-bottom">
<h3 class="widget-heading"><i class="gi gi-cardio text-dark push-bit"></i> <br><small>17k Sales</small></h3>
</div>
<div class="col-xs-4 push-inner-top-bottom border-left">
<h3 class="widget-heading"><i class="gi gi-life_preserver text-dark push-bit"></i> <br><small>3k+ Tickets</small></h3>
</div>
</div>
</div>-->
</div>
And then this code triggers the '.js' file
<script>$(function(){ ReadyDashboard.init(); });</script>
And then this is the javascript snippet
var chartClassicDash = $('#chart-classic-dash');
// Data for the chart
var dataEarnings = [[1, 2300], [2, 2300], [3, 3200], [4, 2500], [5, 4200], [6, 3100], [7, 3600], [8, 2500], [9, 4600], [10, 3700], [11, 4200], [12, 5200]];
var dataSales = [[1, 850], [2, 750], [3, 1500], [4, 900], [5, 1500], [6, 1150], [7, 1500], [8, 900], [9, 1800], [10, 1700], [11, 1900], [12, 2550]];
var dataTickets = [[1, 130], [2, 330], [3, 220], [4, 350], [5, 150], [6, 275], [7, 280], [8, 380], [9, 120], [10, 330], [11, 190], [12, 410]];
var dataMonths = [[1, 'Jan'], [2, 'Feb'], [3, 'Mar'], [4, 'Apr'], [5, 'May'], [6, 'Jun'], [7, 'Jul'], [8, 'Aug'], [9, 'Sep'], [10, 'Oct'], [11, 'Nov'], [12, 'Dec']];
// Classic Chart
$.plot(chartClassicDash,
[
{
label: 'Sales',
data: dataEarnings,
lines: {show: true, fill: true, fillColor: {colors: [{opacity: .6}, {opacity: .6}]}},
points: {show: true, radius: 5}
},
{
label: 'Deposits',
data: dataSales,
lines: {show: true, fill: true, fillColor: {colors: [{opacity: .6}, {opacity: .6}]}},
points: {show: true, radius: 5}
},
{
label: 'Withdrawal',
data: dataTickets,
lines: {show: true, fill: true, fillColor: {colors: [{opacity: .6}, {opacity: .6}]}},
points: {show: true, radius: 5}
}
],
{
colors: ['#5ccdde', '#454e59', '#ffffff'],
//colors: ['#5ccdde', '#deb25c', '#de815c'],
legend: {show: true, position: 'nw', backgroundOpacity: 0},
grid: {borderWidth: 0, hoverable: true, clickable: true},
yaxis: {show: false, tickColor: '#f5f5f5', ticks: 3},
xaxis: {ticks: dataMonths, tickColor: '#f9f9f9'}
}
);
I want to dynamically control these values
// Data for the chart
var dataEarnings = [[1, 2300], [2, 2300], [3, 3200], [4, 2500], [5, 4200], [6, 3100], [7, 3600], [8, 2500], [9, 4600], [10, 3700], [11, 4200], [12, 5200]];
var dataSales = [[1, 850], [2, 750], [3, 1500], [4, 900], [5, 1500], [6, 1150], [7, 1500], [8, 900], [9, 1800], [10, 1700], [11, 1900], [12, 2550]];
var dataTickets = [[1, 130], [2, 330], [3, 220], [4, 350], [5, 150], [6, 275], [7, 280], [8, 380], [9, 120], [10, 330], [11, 190], [12, 410]];
Thanks once again