Google Charts 可以支持双 y 轴(v 轴)吗? [英] Can Google Charts support dual y-axis (v-axis)?

查看:25
本文介绍了Google Charts 可以支持双 y 轴(v 轴)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Flot 图表 api 支持双 v 轴刻度,如 这个例子.

The Flot chart api supports dual v-axis scales, as shown by this example.

我正在使用 Google Charts - 这是否也适用于 Google?我已经浏览了示例和文档,但找不到任何示例/参考资料表明它确实支持双轴图表.

I'm using Google Charts - is this possible also with Google? I've had a look through the examples and docs, but can't find any examples / references to indicate it does support dual axis charts.

推荐答案

我花了一段时间才弄明白,但 Google Charts 确实 支持双 Y 轴(v 轴).我想使用 Javascript API 而不是 HTML 界面.

It took me a while, to figure this out, but Google Charts does support dual Y-axis (v-axis). I want to use the Javascript API and not the HTML interface.

这个例子可以在这里测试:http://code.google.com/apis/ajax/playground/?type=visualization#line_chart

This example can be tested here: http://code.google.com/apis/ajax/playground/?type=visualization#line_chart

将所有代码替换为显示如何使用两个不同 Y 轴刻度的代码:

Replace all of that code with this code showing how to have two different Y-axis scales:

function drawVisualization() {
  // Create and populate the data table.
  var data = new google.visualization.DataTable();
  data.addColumn('string', 'x');
  data.addColumn('number', 'Cats');
  data.addColumn('number', 'Blanket 1');
  data.addColumn('number', 'Blanket 2');
  data.addRow(["A", 1, 1, 0.5]);
  data.addRow(["B", 2, 0.5, 1]);
  data.addRow(["C", 4, 1, 0.5]);
  data.addRow(["D", 8, 0.5, 1]);
  data.addRow(["E", 7, 1, 0.5]);
  data.addRow(["F", 7, 0.5, 1]);
  data.addRow(["G", 8, 1, 0.5]);
  data.addRow(["H", 4, 0.5, 1]);
  data.addRow(["I", 2, 1, 0.5]);
  data.addRow(["J", 3.5, 0.5, 1]);
  data.addRow(["K", 3, 1, 0.5]);
  data.addRow(["L", 3.5, 0.5, 1]);
  data.addRow(["M", 1, 1, 0.5]);
  data.addRow(["N", 1, 0.5, 1]);


  // Create and draw the visualization.
  new google.visualization.LineChart(document.getElementById('visualization')).
      draw(data, {curveType: "function", width: 500, height: 400,
    vAxes: {0: {logScale: false},
            1: {logScale: false, maxValue: 2}},
    series:{
       0:{targetAxisIndex:0},
       1:{targetAxisIndex:1},
       2:{targetAxisIndex:1}}}
          );
}

通过将 maxValue: 2 添加到代码中,并设置系列 1 &2 到那个轴,它们在第二个轴上正常工作.

By adding maxValue: 2 to the code, and setting series 1 & 2 to that axis, they work properly on a second axis.

这篇关于Google Charts 可以支持双 y 轴(v 轴)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆