How to prevent legend labels being cut off in Google charts
Asked Answered
E

2

25

With a Perl script I generate numerous Google Line Charts for 20 and more series of data at once.

The legend labels are of the form: a serial number appended by an iterating #counter.

Unfortunately, starting with #10 those counters are cut off:

enter image description here

Is there maybe a way to stop Google charts from doing that?

My quite simple chart code is below:

    var data = { ...... };

    function drawCharts() {
            for (var csv in data) {
                    var x = new google.visualization.DataTable(data[csv]);

                    var options = {
                            title: csv,
                            width: 800,
                            height: 600
                    };

                    var chart = new google.visualization.LineChart(document.getElementById(csv));
                    chart.draw(x, options);
            }
    }

    $(function() {
            google.setOnLoadCallback(drawCharts);
    });
Elgin answered 7/6, 2013 at 8:53 Comment(1)
have you tried changing the options for ChartArea? Try setting ChartArea.Right to various values and see if it still cuts off.Lacework
A
42

To get full legend in your chart just add chartArea width and height as below

var options = {
              title: csv,
              width: 800,
              height: 600,
              chartArea: {  width: "50%", height: "70%" }
};

Take a look at this jqfaq.com to get a working sample

Avesta answered 27/6, 2013 at 8:27 Comment(2)
Expanding the chartArea option to a width of 100% solved the problem for me. Contrary to the documentation, the chartArea does include the legend. I used a PieChart but the same option is available for the LineChart. var options = {'title':title,'width':w,'height':h,'chartArea':{left:0,top:10,width:"100%"}}; var chart = new google.visualization.PieChart(document.getElementById(chartDiv)); chart.draw(data,options);Unlock
For some reason, this chartArea command is affecting nothing for us. Here is how we are sending it. 'chartArea': {'width': '100%', 'height': '20%'} Any other ideas would be great.Merrymaking
P
0

in chartArea, make width 30 percent move the graph to the center.

chartArea: { width: "30%", height: "50%" }

Puttier answered 21/7, 2017 at 14:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.