简体   繁体   English

在谷歌可视化组合图中如何删除左侧填充而不删除Vaxis标签

[英]In google visualization combo charts how do I remove the left padding without removing the Vaxis labels

I have a combo chart that I'm calling with a chartwrapper, and it centers the chart in the area it's given. 我有一个用chartwrapper调用的组合图表,它将图表放在指定区域内。 I'd like to move it to the left, but when I try 我想将其向左移动,但是当我尝试

chartArea: {left:0},

The values on the Y axis/V axis gridlines get cut off. Y轴/ V轴网格线上的值将被切除。

Is there a way I can shift the chart and all the elements to the left? 有没有办法将图表和所有元素向左移动?

I'm using google visualization code playground and this is my not working code. 我正在使用Google可视化代码游乐场,这是我无法正常工作的代码。 I was trying to get the width of vAxis and it's not working but any method to shift the whole chart left and not cutting off the values or putting the values inside the chart would be great, 我试图获取vAxis的宽度,但它不起作用,但是任何将整个图表向左移动而不切掉值或将值放在图表内的方法都很好,

function drawVisualization() {
var data = google.visualization.arrayToDataTable([
['Month', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua New Guinea', 'Rwanda', 'Average'],
['2004/05',  165,      938,         522,             998,           450,      614.6],
['2005/06',  135,      1120,        599,             1268,          288,      682],
['2006/07',  157,      1167,        587,             807,           397,      623],
['2007/08',  139,      1110,        615,             968,           215,      609.4],
['2008/09',  136,      691,         629,             1026,          366,      569.6]
]);

var wrapper = new google.visualization.ChartWrapper({
chartType: 'ComboChart',
dataTable: data,
options: {
          seriesType: "bars",
          series: {5: {type: "line"}}
         },
containerId: 'visualization'
});
 wrapper.draw();

var charm = wrapper.getChart();

var chi=charm.getChartLayoutInterface();

var width=cli.getBoundingBox('vAxis').width;
wrapper.setOption('chartArea.left','width');
wrapper.draw();
}

The debug code is telling me charm is null 调试代码告诉我魅力为空

You are close. 你近了 You need to stick the position-setting code in a ready event listener for the wrapper, as the chart object seems to be created in an asynchronous process, so it is not guaranteed to exist yet when you call wrapper.getChart() (this is why your debug says charm is null). 您需要将位置设置代码粘贴到包装的ready事件侦听器中,因为图表对象似乎是在异步过程中创建的,因此,当您调用wrapper.getChart()时,尚不能保证该对象已经存在(这是为什么您的调试说的charm为空)。 Also, you want to get the bounding box of vAxis#0#label , not vAxis . 另外,您想获取vAxis#0#label的边界框,而不是vAxis The fixed code looks like this: 固定代码如下所示:

function drawVisualization() {
    var data = google.visualization.arrayToDataTable([
        ['Month', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua New Guinea', 'Rwanda', 'Average'],
        ['2004/05',  165,      938,         522,             998,           450,      614.6],
        ['2005/06',  135,      1120,        599,             1268,          288,      682],
        ['2006/07',  157,      1167,        587,             807,           397,      623],
        ['2007/08',  139,      1110,        615,             968,           215,      609.4],
        ['2008/09',  136,      691,         629,             1026,          366,      569.6]
    ]);

    var wrapper = new google.visualization.ChartWrapper({
        chartType: 'ComboChart',
        dataTable: data,
        options: {
            seriesType: "bars",
            series: {5: {type: "line"}}
        },
        containerId: 'visualization'
    });

    var runOnce = google.visualization.events.addListener(wrapper, 'ready', function () {
        google.visualization.events.removeListener(runOnce);
        var charm = wrapper.getChart();

        var cli = charm.getChartLayoutInterface();
        var width = cli.getBoundingBox('vAxis#0#label').width;
        wrapper.setOption('chartArea.left', width);
        wrapper.draw();
    });

    wrapper.draw();
}

See a working example here: http://jsfiddle.net/asgallant/KwG5N/ 在此处查看工作示例: http : //jsfiddle.net/asgallant/KwG5N/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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