javascript - Getting time series graph for 'On' and 'Off status' with help of google charts -


i have production line have 2 states 'on' , 'off'. have data when production line 'on' , how long. data in following format

data= [[new date("2017-09-11t10:58:14.580+03:00"),8],  [new date("2017-09-11t10:59:22.013+03:00"), 16],  [new date("2017-09-11t11:13:23.344+03:00"), 18],  [new date("2017-09-11t11:14:00.608+03:00"), 6],  [new date("2017-09-11t11:14:18.877+03:00"), 20],  [new date("2017-09-11t11:14:29.214+03:00"), 16]];

so first element in array shows time when(time) production line 'on' , second element shows number of seconds 'on'. want graph can show 'on' status desired amount of seconds 1 below. how can achieved google charts or other. appreciatedenter image description here

p.s:write managed line chart not write depiction.

to shape need using google charts,

you need 5 rows of data per data point

1) start line @ zero
2) move on
3) move across # of seconds
4) bring down off
5) create break until next data point

it difficult label x-axis,
give space between points

see following working snippet...

google.charts.load('current', {    callback: drawchart,    packages: ['corechart']  });    function drawchart() {    var data = [      [new date("2017-09-11t10:58:14.580+03:00"), 8],      [new date("2017-09-11t10:59:22.013+03:00"), 16],      [new date("2017-09-11t11:13:23.344+03:00"), 18],      [new date("2017-09-11t11:14:00.608+03:00"), 6],      [new date("2017-09-11t11:14:18.877+03:00"), 20],      [new date("2017-09-11t11:14:29.214+03:00"), 16]    ];      var datatable = new google.visualization.datatable();    datatable.addcolumn('date', 'time');    datatable.addcolumn('number', 'on');      var xticks = [];    data.foreach(function (row, index) {      // add begin & end ticks      xticks.push(row[0]);      xticks.push(new date(row[0].gettime() + (row[1] * 1000)));        // add rows      // start line @ 0      datatable.addrow([row[0], 0]);        // move line 1      datatable.addrow([row[0], 1]);        // move line across number of seconds      datatable.addrow([new date(row[0].gettime() + (row[1] * 1000)), 1]);        // bring line down 0      datatable.addrow([new date(row[0].gettime() + (row[1] * 1000)), 0]);        // break line      datatable.addrow([new date(row[0].gettime() + (row[1] * 1000)), null]);    });      var chart = new google.visualization.linechart(document.getelementbyid('chart1'));    chart.draw(datatable, {      chartarea: {        bottom: 60      },      haxis: {        format: 'h:s',        slantedtext: true,        ticks: xticks      },      vaxis: {        ticks: [          {v: 0, f: 'off'},          {v: 1, f: 'on'},          {v: 2, f: ''}        ]      }    });  }
<script src="https://www.gstatic.com/charts/loader.js"></script>  <div id="chart1"></div>


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -