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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 解决一个加好友限制问题 或者有好的方案
    • ¥15 关于#java#的问题,请各位专家解答!
    • ¥15 急matlab编程仿真二阶震荡系统
    • ¥20 TEC-9的数据通路实验
    • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
    • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
    • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
    • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
    • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
    • ¥30 求解达问题(有红包)