Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why do i get scroll bars when using google line chart?

I am using google line chart api and no matter how big i make the div chart dimentions, it always shows a horizontal and vertical scroll bar. how can i stop this from happening.

enter image description here

like image 330
leora Avatar asked Apr 21 '26 20:04

leora


2 Answers

CONTEXT: editable HTML of https://code.google.com/apis/ajax/playground/?type=visualization#line_chart (using Firefox or Chorme).

Instructions for help you in the problem:

  • suppose you need a box with width=500px and height=400px.
  • check Javascript at new google.visualization.LineChart(), if the width and height inicializations are 500 and 400.
  • check if style of the HTML tag (perhaps div) of renderization place (id="visualization") is style="width: 800px; height: 400px;".
  • check if style of the HTML parent tag (any) of renderization place is bigger than 500 and 400, or is 100%.

Another solution is by "HTML cut": use overflow:hidden.

EXAMPLE OF CASE WITH SCROLL

        // ... piece of your javacascript.
    new google.visualization.LineChart(document.getElementById('visualization')).
        draw(data, {curveType: "function",
                    width: 800, height: 400,
                    vAxis: {maxValue: 10}}
            );
    } google.setOnLoadCallback(drawVisualization);
<!-- ... piece of your HTML -->
<div id="container" style="width:400px;overflow:scroll;">
  <div id="visualization" style="width: 800px; height: 400px;"></div>
</div>

HTML SOLUTION (fix the container width)

<!-- ... piece of your HTML -->
<div id="container" style="width:800px;overflow:scroll;">
  <div id="visualization" style="width: 800px; height: 400px;"></div>
</div>

ANOTHER SIMPLE HTML SOLUTION (use overflow:hidden)

<!-- ... piece of your HTML -->
<div id="container" style="width:400px;overflow:hidden;">
  <div id="visualization" style="width: 800px; height: 400px;"></div>
</div>

... or reduce all, Javascript and HTML widths and heights, etc.

like image 154
Peter Krauss Avatar answered Apr 25 '26 12:04

Peter Krauss


Using :

<script src="https://www.google.com/jsapi"></script>
<script>
  google.load("visualization", "1", {packages:["corechart"]});
var data = new google.visualization.DataTable();
//init your data
var options = {
      width: "100%", height: "100%",
      //other options

}
var chart = new google.visualization.LineChart(document.getElementById('chart'));
chart.draw(data, options);
</script>
....

<body>
   <div id="chart"></div>
</body>

You ensure that the graph will fit the div you're using.

Then to resize the graph set style="width: ...px; height: ...px;" with the desired size :

<body>
  <div style="width: 800px; height: 400px;" id="chart"></div>
</body>
like image 43
alain.janinm Avatar answered Apr 25 '26 11:04

alain.janinm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!