Google chart timeline with date in x axis

user3270211

Working on a google line chart. The problem I have came into is that the chart on shows values of one day, have not implemented timeline with dates. I understand that the chart will be wide if your getting values from for example one week, is there any way to solve that ? I was thinking of something like this ?

enter image description here

How its looking right now:

enter image description here

Database: ( the date is saved as date in phpadmin)

enter image description here

Code:

<?php

$con=mysql_connect("localhost","root","") or die("Failed to connect with database!!!!");
mysql_select_db("chart", $con);

$sth = mysql_query("SELECT * FROM googlechart");

$rows = array();
//flag is not needed
$flag = true;
$table = array();
$table['cols'] = array(

 // Labels for your chart, these represent the column titles
    // Note that one column is in "string" format and another one is in "number" format as pie chart only required "numbers" for calculating percentage and string will be used for column title
    array('label' => 'Time',    'type' => 'number'),
    array('label' => 'PH',      'type' => 'number'),
    array('label' => 'temperature','type' => 'number'), 
    array('label' => 'Chlorine','type' => 'number'),

    );

    $rows = array();

while($r = mysql_fetch_assoc($sth)) {
     $temp = array();
        $temp[] = array('v' => (string) $r['Time']); 
        $temp[] = array('v' => (string) $r['PH']);
        $temp[] = array('v' => (string) $r['temperature']);
        $temp[] = array('v' => (string) $r['Chlorine']);


        $temp[] = array('v' => (int) $r['Time']);   
        $rows[] = array('c' => $temp);

}

 $table['rows'] = $rows;
 $jsonTable = json_encode($table);
 echo $jsonTable;   

?>


<html>
  <head>

    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);

      function drawChart() {
        var data = new google.visualization.DataTable(<?=$jsonTable?>);

        var options = {
        /*width: 900, height: 900, */
          title: 'Visualization',
          /* curveType: 'function', */
           legend: { position: 'bottom' },
           pointSize: 10,
        vAxis: {title: "Values", titleTextStyle: {italic: false}},
        hAxis: {title: "Time", titleTextStyle: {italic: false}},
        };

        var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
        chart.draw(data, options);


      }
    </script>
  </head>
  <body>
    <div id="chart_div" style="width: 900px; height: 500px;"></div>
  </body>
</html>
Anto Jurković

You can get part of what you want using format property of hAxis, for example:

hAxis: {
    format: "HH:mm",
    ...
}

See line chart configuration options for hAxis.format.

Update: Example at jsbin

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Google chart timeline with date in x axis

From Dev

Google Chart Timeline floating X-axis

From Dev

Excel Chart, X Axis timeline spacing

From Dev

Google Timeline chart: two horizontal axis

From Dev

Passing Date field to google chart timeline

From Dev

Google timeline chart starting from wrong date

From Dev

Using timeline Google Chart API in PHP - Date/Time formatting issues

From Dev

Line Chart with Int as x axis, not Date

From Dev

high chart date format in x-axis

From Dev

Google Chart: is it possible to use Strings for the x axis?

From Dev

Google chart x axis label text

From Dev

set x Axis range in google chart

From Dev

google chart with proportional X-axis

From Dev

d3 timeline axis - line chart bug with animation - x.bandwidth error

From Dev

Customizing tooltip on Google Timeline Chart

From Dev

Google timeline chart duration in hour

From Dev

Chart line morris.js format date in X axis

From Dev

Highcharts - Column chart with empty columns for date in x-axis

From Dev

How to load an Area Chart when the x-axis is date?

From Dev

Highcharts (highstock) plotting incorrect date on x-axis line chart

From Dev

How to extract date on X axis from a point on chart [mschart]

From Dev

dimple js x-axis date issue with bar chart

From Dev

Pentaho - How to show complete date in line chart's X axis

From Dev

vb.net Sort Chart By X Axis Date

From Dev

Duplicate label on x-axis, stacking bar chart (google charts)

From Dev

How to display Google column chart x-axis label vertically?

From Dev

Google Bar Chart Moving x-axis labels to Top

From Dev

Real-time moving x axis using google line chart

From Dev

Calculated text column for Google Line Chart x-axis not working

Related Related

HotTag

Archive