<?php
  //  $host="localhost";
//	$user="llprecha_llpuser";
//	$pass="Pwd@9897095971";
	//$db="llprecha_llp";
/* Include the `fusioncharts.php` file that contains functions  to embed the charts. */

   include("fusioncharts.php");

/* The following 4 code lines contain the database connection information. Alternatively, you can move these code lines to a separate file and include the file here. You can also modify this code based on your database connection. */

   $hostdb = "localhost";  // MySQl host
   $userdb = "llprecha_llpuser";  // MySQL username
   $passdb = "Pwd@9897095971";  // MySQL password
   $namedb = "llprecha_llp";  // MySQL database name

   // Establish a connection to the database
   $dbhandle = new mysqli($hostdb, $userdb, $passdb, $namedb);

   /*Render an error message, to avoid abrupt failure, if the database connection parameters are incorrect */
   if ($dbhandle->connect_error) {
    exit("There was an error with your connection: ".$dbhandle->connect_error);
   }
?>

<html>
  <head>
    <title>FusionCharts XT - Column 2D Chart - Data from a database</title>
    <!--<link  rel="stylesheet" type="text/css" href="style.css" />
    <!-- You need to include the following JS file to render the chart.
    When you make your own charts, make sure that the path to this JS file is correct.
    Else, you will get JavaScript errors. -->
    <script src=" https://cdn.fusioncharts.com/fusioncharts/latest/fusioncharts.js"></script>
    <script src=" https://cdn.fusioncharts.com/fusioncharts/latest/themes/fusioncharts.theme.fusion.js"></script>
  </head>
   <body>
    <?php
      // Form the SQL query that returns the top 10 most populous countries
      //$strQuery = "SELECT * FROM recharge ORDER BY Id DESC LIMIT 30";

      // Execute the query, or else return the error message.
      //$result = $dbhandle->query($strQuery) or exit("Error code ({$dbhandle->errno}): {$dbhandle->error}");

      // If the query returns a valid response, prepare the JSON string
      
          // The `$arrData` array holds the chart attributes and data
          $arrData = array(
              "chart" => array(
                  "caption" => "Total Transaction By Date Of This Month",
                  "showValues" => "0",
                  "theme" => "fusion"
                ));
            

          $arrData["data"] = array();

  // Push the data into the array//
            include'connection.php';
            include'time.php';
            
            $day=substr($date,8,2);
          for($i=1; $i<=$day; $i++)
          {
              $TxnDate=date_create("2020-07-$i");
              $RealTxnDate=date_format($TxnDate, "Y-m-d");
              $TotalTxn=0;
              $quGetTxn="select * from recharge where Status='SUCCESS' and Userid='500012' and Rechargedate='$RealTxnDate'";
              $reGetTxn=mysqli_query($con, $quGetTxn);
              while($dataGetTxn=mysqli_fetch_array($reGetTxn))
              {
                  $Txn=$dataGetTxn['Amount'];
                  $TotalTxn=$TotalTxn+$Txn;
              }
              
              
            array_push($arrData["data"], array(
                "label" => $i,
                "value" => $TotalTxn
                )
            );
          }

          /*JSON Encode the data to retrieve the string containing the JSON representation of the data in the array. */

          $jsonEncodedData = json_encode($arrData);

  /*Create an object for the column chart using the FusionCharts PHP class constructor. Syntax for the constructor is ` FusionCharts("type of chart", "unique chart id", width of the chart, height of the chart, "div id to render the chart", "data format", "data source")`. Because we are using JSON data to render the chart, the data format will be `json`. The variable `$jsonEncodeData` holds all the JSON data for the chart, and will be passed as the value for the data source parameter of the constructor.*/

          $columnChart = new FusionCharts("column2D", "myFirstChart" , 1200, 500, "chart-1", "json", $jsonEncodedData);

          // Render the chart
          $columnChart->render();

          // Close the database connection
          $dbhandle->close();
      
    ?>
    <div class="chart" id="chart-1"><!-- Fusion Charts will render here--></div>\
   </body>
</html>
