dongxindu8753 2014-12-16 12:01
浏览 18

Flot Stacked Bar显示一周的数据

The purpose is to display data into flot stacked bar. For example for Week1 I would be able to count number of red, orange and green color and display them into stacked bar and by having week1 underneath the x-axis.

My code is working fine between two flexible dates so for example starting date is "1/1/2015" and the end date is "1/7/2015".

Wondering how to display it as weekly regarding to the dates I have chosen.

Any examples would be much appreciated.

Thank you.

Here is my code for PHP :-

 $result = mysqli_query($con,"SELECT * FROM `colors` WHERE  `Date` BETWEEN  '" . $_POST   
 ['start'] . "' AND  '" . $_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 is my JavaScript code:-

 (function($) {
   var series = [{
    // Data needs to be displayed in te Stacked Bar.
    // counterRed : to count the color for Red
    data: [[ 1,<?php echo $counterRed; ?>] ],
     valueLabels: {
    show: true,
    valign: 'middle'
     }     ,
     label: "Red" , 
    color:'#2AD457'
    },
     {
     //counterOrange to count the color for Orange
     data: [[1,<?php echo $counterOrange; ?>] ], 
     valueLabels: {
    show: true,
    valign: 'middle'
     }     ,

    label: "Orange" ,
    color:'#FFC200'
     }, {
    // CounterGreen : to count the Color for Green.
    data: [[1,<?php echo $counterHigh; ?>] ],
     //ValueLables used to show the values of color into each series of the 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);    
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!