如何防止在Google图表中切断图例标签(How to prevent legend labels being cut off in Google charts)

其他开发 IT屋
问 题

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);
    });
解决方案

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

本文地址:IT屋 » How to prevent legend labels being cut off in Google charts

问 题

使用Perl脚本,我会生成大量的 Google线图以及更多系列的数据。



图例标签的格式为:由迭代#counter附加的序列号。

不幸的是,从#10开始,这些计数器被切断:


$ b

b $ b

我的简单图表代码如下:

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

函数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);
});

解决方案

要在图表中获得完整的图例,只需添加chartArea宽度和高度如下



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


查看 jqfaq.com 得到一份工作样本


本文地址:IT屋 » 如何防止在Google图表中切断图例标签