php - Flot Stacked Bar Show Data for a Week -
the purpose display data flot stacked bar. example week1 able count number of red, orange , green color , display them stacked bar , having week1 underneath x-axis.
my code working fine between 2 flexible dates example starting date "1/1/2015" , end date "1/7/2015".
wondering how display weekly regarding dates have chosen.
any examples appreciated.
thank you.
here code php :-
$result = mysqli_query($con,"select * `colors` `date` between '" . $_post ['start'] . "' , '" . $_post ['end'] . "' ") or die ("error: ".mysqli_error($con)); $colorcounter = 0; $counterred=0; $counterorange=0; $countergreen=0; while($row = mysqli_fetch_array($result)) { $answer = $row['color']; $red= 'red'; $orange='orange'; $green='green'; if ($answer == $red) { $counterred++; } if($answer == $orange) { $counterorange++; } if($answer == $green) { $countergreen++; } $colorcounter; } mysqli_close($con);
javascript libraries :-
<script src="../../js/jquery.flot.js"></script> <script src="../../js/jquery.flot.stack.js"></script> <script src="../../js/jquery.flot.valuelabels.js"></script> <script src="../../js/jquery.flot.categories.min.js"></script>
here javascript code:-
(function($) { var series = [{ // data needs displayed in te stacked bar. // counterred : count color red data: [[ 1,<?php echo $counterred; ?>] ], valuelabels: { show: true, valign: 'middle' } , label: "red" , color:'#2ad457' }, { //counterorange count color orange data: [[1,<?php echo $counterorange; ?>] ], valuelabels: { show: true, valign: 'middle' } , label: "orange" , color:'#ffc200' }, { // countergreen : count color green. data: [[1,<?php echo $counterhigh; ?>] ], //valuelables used show values of color each series of bar. valuelabels: { show: true, valign: 'middle' } , label: "green" , color:'#fa0509' }]; var options = { xaxis: { minticksize: 1 }, series: { bars: { show: true, barwidth: .8, align: "center" }, stack: true } }; $.plot("#placeholder", series, options); })(jquery);
Comments
Post a Comment