简体   繁体   中英

How to create a continuous line in a bar chart using combocharts?

Here's my code, I want to create a continuous line like a goal in my chart, I followed the example posted in Google Charts . Do I need to create a function to do that?

function drawChart() {
  var data = google.visualization.arrayToDataTable([
  ['Task', 'Hours per Day'],
  ['Work', 8],
  ['Eat', 2],
  ['TV', 4],
  ['Gym', 2],
  ['Sleep', 8]
]);

  var options = {
  title:'My Average Day',
  vAxis: {title: 'Tasks'},
  hAxis: {title: 'Hours per Day'},
  seriesType:'bar',
  series:{4:{type:'line'}}
  };

  var chart = new google.visualization.ComboChart(document.getElementById('chart1'));
  chart.draw(data, options);
}

seriesType should be "bars" not "bar" and your data should looks like this to draw line for 'Sleep' for example:

  google.charts.load('current', {'packages':['corechart']}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ['Task', 'Hours per Day', 'Sleep'], ['Work', 8, 8], ['Eat', 2, 8], ['TV', 4, 8], ['Gym', 2, 8], ]); var options = { title:'My Average Day', vAxis: {title: 'Tasks'}, hAxis: {title: 'Hours per Day'}, seriesType:'bars', series:{1:{type:'line'}} }; var chart = new google.visualization.ComboChart(document.getElementById('chart1')); chart.draw(data, options); } 
 <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <div id="chart1" style="width: 900px; height: 500px;"></div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM