Question

i make a line chart in php i want to add custom date in which i select the start date and end date and chart shown according to that dates,how i do this? here is my code:

 <?php
 $title='Product Management';
 include("merchantheader.php");
 include("DBConn.php");
 include("FusionCharts.php");
 $link = connectToDB();
 $strQuery="select Distinct DATE_FORMAT(transactions.transaction_date,'%c-%d-%Y') as transaction_date,sum(amount)as Amount from transactions group by  DATE_FORMAT(transactions.transaction_date,'%c-%d-%Y')";
    $result = mysql_query($strQuery) or die(mysql_error());
    $strXML = "<chart caption='Reports of transactions' showValues='0' useRoundEdges='1' palette='3'>";
    while($ors = mysql_fetch_assoc($result)){
    //Generate <set label='..' value='..' />
    $strXML .= "<set label='" .$ors['transaction_date'] ."' value='" . $ors['Amount'] ."' />";
    }
    //free the result set
    //mysql_free_result($result);
    //mysql_close($link);
    //Finally, close <chart> element
    $strXML .= "</chart>";

    //date_default_timezone_set($_SESSION['timezone']);
?>
<?php /*?><textarea ><?php print_r($strXML); ?></textarea><?php */?>    
    <!-- Include FusionCharts.js to provide client-side interactivity -->
    <script type="text/javascript" src="<?=MURL?>/Charts/FusionCharts.js"></script>  
    <link href="<?=MURL?>/assets/ui/css/style.css" rel="stylesheet" type="text/css" /> 
    <script type="text/javascript" src="<?=MURL?>/assets/ui/js/jquery.min.js"></script>
<script type="text/javascript" src="<?=MURL?>/assets/ui/js/lib.js">  </script>     
   <link rel="Stylesheet" type="text/css" href="<?=MURL?>/css/jpicker-1.1.6.min.css" />
<link rel="Stylesheet" type="text/css" href="<?=MURL?>/css/jPicker.css" />
<script src="<?=MURL?>/js/jpicker-1.1.6.min.js" type="text/javascript"></script>
  <div id="chartContainer">
 <?php
 FC_SetRenderer('javascript');
 echo renderChart('Charts/Line.swf', // Path to chart type
                '',         // Empty string when using Data String Method
                $strXML,    // Variable that contains XML string
                'Tracking', // Unique chart ID
                '850', '400', // Width and height in pixels
                false,      // Disable debug mode
                true        // Enable 'Register with JavaScript' (Recommended)
            );

?>

i want to make custom date range like the picture given below:

enter image description here

Was it helpful?

Solution

If you are willing to display the dates for some data points and not for all, you could set the "labelStep" attribute to some value 'n' in the chart element of your XML data, by which you can opt to show every n-th label.

However, as per your screen shot, the third label "Nov" will not come in regular interval which is multiple of 'n'. So, for this case, you need to programmatically put a condition and set the "showLabel" attribute to "1" in the element, while generating the chart XML string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top