Bhavin
Bhavin

Reputation: 2158

Adding value to high chart's Spline Graph from mysql

My selected rows from query is,

 ## Selected rows from query ##
        id             rank          Date
        2               5           2016-03-15    
        4               3           2016-04-15
        5               2           2016-04-15

My Query is,

$touserid = '26'; $teamcode = "RXqYLM";

Query = select *,SUM(rank_emotions) as total from assign_emotions where to_user_id='$touserid' and teamcode='$teamcode';

So, i got total perfectly but the problem is i want show months in the graph so for months i done.

              $date = $row['date'];
              $time = strtotime($date);
              $month = date("F",$time);  

So From this code i got month now the problem is i have to combine both and i want monthwise rank of user and show it in Graph.

I tried below code, but i want monthwise rank it means if in one month if a user has more than one rank that those values must be sum so in datafield's example for April month the rank is 8.

 <?php 
      include("header.php");
      include("config.php"); 
      $touserid = '26';
      $teamcode = "RXqYLM";
      $name = $_POST['teammembername'];
      if(isset($_POST['teammembername']))
      {
          $touserid = '26';
          $teamcode = "RXqYLM";
          $name = $_POST['teammembername'];

          $res = $conn -> query("select *,SUM(rank_emotions) as total, MONTH(date) as month from assign_emotions where to_user_id='$touserid' and teamcode='$teamcode' GROUP BY MONTH(date)");
          $counter = 0;
           while($row = mysqli_fetch_assoc($res))
          {
            echo $row['month'];
          }
        }
?>    

<!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
        <script src="https://code.highcharts.com/highcharts.js"></script>
        <script src="https://code.highcharts.com/highcharts-more.js"></script>
        <script src="https://code.highcharts.com/modules/exporting.js"></script>
    </head> 
    <body>
    <script>
    $(function () {
        $('#container').highcharts({
            chart: {
                type: 'spline'
            },
            title: {
                text: 'KPI Chart Monthwise'
            },
            xAxis: {
                categories: ['Jan', 'Feb', 'March', 'April', 'May','June', 'July', 'August', 'September', 'October', 'Nov', 'December']
            },
            credits: {
                enabled: false
            },
            series: [{
                name: '<?php echo "bhavin"; ?>',
                data: [<?php if($row['month'] == '1')
                    {
                       echo $row['total'];
                    }
                    else
                    {
                        echo '0';
                    } ?>, 3, 4, 7, 2, 0, 0, 0, 0, -2, 0 ,0]
            }]
        });
    });
    </script>
    <div id="container" style="height: 400px; margin: auto; min-width: 310px; max-width: 600px"></div>
    </body>
    </html>

if there is any doubt in the question please let me know .

Upvotes: 0

Views: 278

Answers (1)

RiggsFolly
RiggsFolly

Reputation: 94662

If you change your query to group the results by the the month

$res = $conn -> query("
    select *,SUM(rank_emotions) as total, MONTH(date) as month
    from assign_emotions 
    where to_user_id='$touserid' 
      and teamcode='$teamcode'
    GROUP BY MONTH(date)");

this will give you the total by each month

Upvotes: 2

Related Questions