First of all, I have a stores table as follows :
Table Name : stores
id |name
1 | M1
2 | M2
And Each store is considered as a table which have its own items, selling price and qty as follows
Table Name : M1
id | item | qty | sell_price
1 | z1 | 12 | 5.00
2 | z2 | 15 | 6.00
Table Name : M2
id | item | qty | sell_price
1 | z1 | 12 | 5.00
2 | z5 | 25 | 12.00
3 | z6 | 5 | 7.00
Now I want to create a bar graph by which I need to see Each store its Total selling price ( SUM(sell_price) ) , as follows :
Y-axis ( Total Sell_price )
30| _____
25| ____ | |
20| | | | |
15| | | | |
0|_|____|__|_____|________ X - axis (Store Name )
M1 M2
I've created the PHP code as follows :
$query1 = "SELECT name from stores";
$result1 = mysql_query($query1);
if(!mysql_num_rows($result1)>0){
echo "<center><font color=red>No Stores Found !</font></center>";
}
else{
while ($row1 = mysql_fetch_assoc($result1)){
$query = "SELECT *,SUM(sell_price) FROM {$row1['name']}";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
$store[]= $row1['name'];
$sale[] = $row['SUM(sell_price)'];
}
}
Bar Graph JavaScript - Please Note var s1 and var ticks are the ones needed to be changed and collects array from the above PHP loop
<script class="code" type="text/javascript">$(document).ready(function(){
$.jqplot.config.enablePlugins = true;
var s1 = [200, 888, 645, 1044];
var ticks = ['M1','M7','M9','M10'];
plot1 = $.jqplot('chart1', [s1], {
// Only animate if we're not using excanvas (not in IE 7 or IE 8)..
animate: !$.jqplot.use_excanvas,
seriesDefaults:{
renderer:$.jqplot.BarRenderer,
pointLabels: { show: true }
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
ticks: ticks
}
},
highlighter: { show: false }
});
$('#chart1').bind('jqplotDataClick',
function (ev, seriesIndex, pointIndex, data) {
$('#info1').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);
}
);
});</script>
Now as you can see, I've created an array $store and $sale - Not sure if its a correct array because i'm not too familiar with arrays. However I need to find how can I assign the array values to javascript vars (s1 and ticks) accordingly.