简体   繁体   English

同一页面上的2个Google图表出现渲染问题

[英]Rendering issue with 2 Google charts on the same page

I have a rendering problem when I have two column material Google charts on the same page. 当我在同一页面上有两个列材质的Google图表时,出现渲染问题。 Basically, the first column gets partially drawn on the vertical line which corresponds to axis of the second chart. 基本上,第一列在与第二张图表的轴相对应的垂直线上部分绘制。 If I have only 1 chart - everything is OK. 如果我只有一张图表-一切正常。

Please take a look at the following screenshots to see the problem: 请查看以下屏幕截图以查看问题:

It seems to be a problem with the different scales on the Y-axis. Y轴上的不同比例似乎是一个问题。 If you look at this example the problem is gone, because the widths of the Y-axis labels of both charts are equal: fiddle1 如果看这个例子,问题就消失了,因为两个图表的Y轴标签的宽度相等: fiddle1

If you force the Y-axis label to a fixed width, using the vAxis.format option for example, the chart is also correctly rendered: fiddle2 如果使用例如vAxis.format选项将Y轴标签强制固定为固定宽度,则图表也将正确呈现: fiddle2

You could try to define a usable format string (refer to the Google documentation for more information), but it seems like a bug in the Google API, see phts's answer for the support page. 您可以尝试定义可用的格式字符串(有关更多信息,请参阅Google 文档 ),但这似乎是Google API中的错误,请参阅phts的支持页面答案

您最好直接在Google Charts项目页面上查找/讲述问题-https: //code.google.com/p/google-visualization-api-issues/issues/list

Here is the thing, the two tables are in the same line and their Y-axis unit confuses the charts styling. 事实是,两个表在同一行中,并且它们的Y轴单位混淆了图表样式。 I mean; 我的意思是;

There are two-digit numbers in the first case [25,34,33,45,...,26] and five-digit numbers in the second case [31209,43658,42007,...30177] These five-digit numbers become strings like 20K,40K... 第一种情况下有两位数字[25,34,33,45,...,26],第二种情况下有五位数[31209,43658,42007,... 30177]这五位数字数字变成像20K,40K这样的字符串...

Thus, problem is in that part. 因此,问题就在于那部分。 One solution can be formatting the numbers as @mhu suggested. 一种解决方案是按照@mhu的建议格式化数字。 Another solution can be using the ColumnChart type by changing the code part; 另一种解决方案是通过更改代码部分使用ColumnChart类型。

var chart = new google.visualization.ColumnChart(document.getElementById('traffic-chart'));
chart.draw(data, google.charts.Bar.convertOptions(options));

and adding this to the options ; 并将其添加到选项中;

hAxis: {viewWindowMode: 'maximize'}

https://jsfiddle.net/L0gxnywu/ https://jsfiddle.net/L0gxnywu/

Solution 2: You can change the div's sequence as; 解决方案2:您可以将div的顺序更改为:

<div id="requests-chart"></div>
<div id="traffic-chart"></div>

https://jsfiddle.net/3j4s1vfj/ https://jsfiddle.net/3j4s1vfj/

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

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