简体   繁体   English

Google Visualization API双Y轴-无法调整targetAxisIndex

[英]Google Visualization API double Y axis - not being able to adjust targetAxisIndex

I am creating a multiple line chart with Google Chart API where I want to use 2 Y axis such as -> 我正在使用Google Chart API创建多条折线图,我想在其中使用2个Y轴,例如-> 在此处输入图片说明 , but with one axis set to max 24000 for my 6 countries, and the second set to 90000 for the 'Total World' column. ,但在我的6个国家/地区中,一根轴设置为max 24000,第二根“ Total World”列设置为90000。

The problem is that my set of options never returns the 'Total World' in the second y axis and the other 6 countries in the first y axis, no matter how I arrange the option 'targetAxisIndex': 问题是,无论我如何排列选项“ targetAxisIndex”,我的选项集都永远不会在第二个y轴上返回“总世界”,而在第一个y轴上则不会返回其他6个国家/地区:

var tot = 95000;
var min = 0, var max = 24000;
.... 

 var options = {
            title: 'Top Consuming Nations - Thousand barrels daily',

            hAxis: {title: 'Year'},
            width: 1050, height : 400,

            vAxes: [
              {title: 'Top Countries', titleTextStyle: {color: '#FF0000'},  maxValue: max},  // Left axis maxValue: 60000
              {title: 'Total World', titleTextStyle: {color: '#FF0000'},  maxValue: tot}  // Right 
            ],
            series:[
              {targetAxisIndex:1},
              {targetAxisIndex:0}
            ],
            legend: { position: 'top', alignment: 'start' }
          };

here is the complete code: http://plnkr.co/edit/u5xXExdkTTYU8fHxWzHB?p=preview 这是完整的代码: http : //plnkr.co/edit/u5xXExdkTTYU8fHxWzHB?p=preview

I found the answer on Google Groups: 我在Google网上论坛中找到了答案:

Hi Chris, 克里斯,你好

The series option is supposed to be a mapping of series index to series options. 系列选项应该是系列索引到系列选项的映射。 When you specify it as an array, you're basically doing that assignment implicitly. 当您将其指定为数组时,基本上就是在隐式地进行该分配。 So in your example, series 0 will go on axis 1, and series 1 will go on axis. 因此,在您的示例中,系列0将在轴1上,而系列1将在轴上。 All other series will go to the default axis (0). 所有其他系列将转到默认轴(0)。 Your issue could be fixed pretty easily, by simply reorganizing your series such that the total is the first. 通过简单地重新组织系列,使总数成为第一,可以很容易地解决您的问题。 Alternatively, you could explicitly specify that series 6 (your total series, 'country6') should go on axis 1. The default is for things to go on axis 0, so you don't need to explicitly specify that. 或者,您可以明确指定系列6(您的总系列为“ country6”)应该位于轴1上。默认情况是事物要位于轴0上,因此您无需明确指定。 Here's an updated version of your plunkr with the second version of the solution (since that was easier for me to do): http://plnkr.co/edit/GhsNcBCtDW0i4OTu0VJR?p=preview 这是您的plunkr的更新版本,带有解决方案的第二个版本(因为对我来说更容易做到): http ://plnkr.co/edit/GhsNcBCtDW0i4OTu0VJR?p=preview

var options = {
            title: 'Top Consuming Nations - Thousand barrels daily',

            hAxis: {title: 'Year'},
            width: 1050, height : 400,

            vAxes: [
              {title: 'Top Countries', titleTextStyle: {color: '#FF0000'},  maxValue: max},  // Left axis maxValue: 60000
              {title: 'Total World', titleTextStyle: {color: '#FF0000'},  maxValue: tot}  // Right 
            ],
            series:{
              6: {targetAxisIndex: 1}
            },
            legend: { position: 'top', alignment: 'start' }
          };

          var chart = new google.visualization.LineChart(document.getElementById(chartDiv));

          chart.draw(data, options);

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

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