javascript - Dual y axes in Google charts -


i trying use dual y axes google charts.i understand basics , how works.

on 1 y axis, want bmi values , on other weight values.

i taking out data sql database. however, bmi , weight values in column called readingname. so, if use query,

select * table readingname = 'bmi' or readingname = weight 

i result set serialized json , forwarded render charts again retrieved using column name only.

now, have observation values bmi on 1 yaxis , weight on other, per example on googlecharts website, need have them columns.

but have them different values of same column called readingtype.is there work around possible ?

this how should : enter image description here

unfortunately, you'll have massage data format understands. datatable class provides lots of methods populating here example:

google.load("visualization", "1", {      packages: ["corechart"]  });  google.setonloadcallback(drawchart);    function drawchart() {      // start long data      var rawdata = [          [new date(2014, 8, 1), "weight", 140],          [new date(2014, 8, 1), "bmi", 5],          [new date(2014, 8, 15), "weight", 130],          [new date(2014, 8, 15), "bmi", 4],                    [new date(2014, 9, 1), "weight", 120],          [new date(2014, 9, 1), "bmi", 3],          [new date(2014, 9, 15), "weight", 120],          [new date(2014, 9, 15), "bmi", 3]      ];            // create wide table long data      var data = new google.visualization.datatable();      data.addcolumn("date", "date");      data.addcolumn("number", "bmi");      data.addcolumn("number", "weight");                  var lastdate = null;      var currentrow = null;      (var i=0; < rawdata.length; i++) {          var date=rawdata[i][0];          var col=rawdata[i][1];          var value=rawdata[i][2];                    if (lastdate == null) {              // first pass              currentrow = [date, null, null];                      }          else if (lastdate != date) {              data.addrow(currentrow);              currentrow = [date, null, null];                }                    if (col=="bmi") currentrow[1] = value;          else if (col=="weight") currentrow[2] = value;                              lastdate = date;      }            if (currentrow != null) data.addrow(currentrow);                    var options = {            title: 'wight & bmi',          vaxes: [{              title: "weight",              minvalue: 0          }, {              title: "bmi",              minvalue: 0          }],          series: {              0: { targetaxisindex:0 },                  1: { targetaxisindex:1 }          },          interpolatenulls: true      }          var chart = new google.visualization.linechart(document.getelementbyid("chart"));      chart.draw(data, options);  }
<script type="text/javascript" src="https://www.google.com/jsapi"></script>  <div id="chart" style="width: 900px; height: 300px;"></div>


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -