Post value with getJSON function to php

42 Views Asked by At

I need to send the new date to the PHP page to update the chart based on the user's choice.

this my js code when load page :

$.getJSON("chart.php", function (data) {

var chart = new CanvasJS.Chart("chartContainer", {
data: [
{                              
 indexLabel: " {y}",
 indexLabelFontSize: 16,
 dataPoints: data
  }
  ]
 });

chart.render();
 });

and this my php code :

     include("config.php");
     
    $data_points = array();  

 $result = mysqli_query($con, "SELECT sub, main, SUM(amount) AS total FROM data GROUP BY sub, main order by total desc LIMIT 15");
    
        while($row = mysqli_fetch_array($result))
        {        
            $point = array("label" => $row['sub'] , "y" => $row['total']);
    
            array_push($data_points, $point);        
        }
    
        echo json_encode($data_points, JSON_NUMERIC_CHECK);

    

I use the chart from https://cdn.canvasjs.com/canvasjs.min.js

When the user selects a date from the calendar, I want to update the chart. How do I do that?

0

There are 0 best solutions below