Set Google Charts legend width in JavaScript - Javascript Google Chart

Javascript examples for Google Chart:Legend

Description

Set Google Charts legend width in JavaScript

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head> 
      <title>Left space for right legend</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <style id="compiled-css" type="text/css">

#chart_div {/* w  w  w  .ja  v a 2  s .  c  o m*/
   width: 400px;
   height: 300px;
   border: 1px solid black;
}


      </style> 
   </head> 
   <body> 
      <script src="https://www.gstatic.com/charts/loader.js" type="text/javascript"></script> 
      <div id="chart_div"></div> 
      <script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
      var data = google.visualization.arrayToDataTable([
         ['Year', 'Total Sales', 'Total Expenses'],
         ['2004', 1000, 400],
         ['2005', 1170, 460],
         ['2006', 660, 1120],
         ['2007', 1030, 540]
    ]);
      var options = {
         title: 'Company Performance',
         curveType: 'function',
         legend: { position: 'right' },
         chartArea: {
              right: 130,    
              left: 60,      
         },
        hAxis: { title: "year" },
        vAxis: { title: "quantity" },
      };
      new google.visualization
          .LineChart(document.getElementById('chart_div'))
            .draw(data, options);
}

      </script>  
   </body>
</html>

Related Tutorials