Google Charts 可以支持双 y 轴(v 轴)吗?

发布于 2024-12-02 10:00:13 字数 263 浏览 0 评论 0原文

Flot 图表 API 支持双 v 轴刻度,如 此示例

我正在使用 Google 图表 - Google 也可以这样做吗?我浏览了示例和文档,但找不到任何示例/参考来表明它确实支持双轴图表。

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陌伤ぢ 2024-12-09 10:00:13

我花了一段时间才弄清楚这一点,但 Google 图表确实支持双 Y 轴(v 轴)。我想使用 Javascript API 而不是 HTML 界面。

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

将所有代码替换为以下代码,显示如何拥有两个不同的 Y 轴刻度:

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 到该轴,它们在第二个轴上正常工作。

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.

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

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

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

生来就爱笑 2024-12-09 10:00:13

非 JavaScript 解决方案

假设您正在寻找共享相同 X 轴(水平)但 Y 轴(垂直)具有不同值(和比例)的系列,那么您可以这样做无需求助于 JavaScript,如下所示:

  1. 选择插入|菜单中的图表。
  2. 双击图表,然后在图表编辑器中选择图表类型 |折线图。
  3. 单击“数据范围”框中的网格图标以获取数据范围对话框。
  4. 单击包含您感兴趣的 Y 轴线数据的工作表,并从左上角到右下角突出显示,以便覆盖所有 Y 轴线。您可以稍后整理列。
  5. 单击“确定”,您将看到已提取系列的集合。使用每个系列的“点菜单”删除您不感兴趣的系列。
  6. 单击“X 轴”框中的网格图标可再次获取数据范围对话框。
  7. 单击包含您对 X 轴线感兴趣的数据的工作表,并从上到下突出显示。
  8. 单击“确定”,您将看到 X 轴已填充,并且两条 Y 轴线共享相同的左轴标签。
  9. 单击要使用右轴标签的线,然后使用图表编辑器对话框中的“轴”框选择“右轴”。

现在,您可以编辑图表的各种其他属性,使其在呈现方式上符合您想要的方式。

Non-JavaScript solution

Assuming that you are looking for a series that shares that same X-axis (horizontal) but has different values (and scales) for the Y-axis (vertical) then you can do this without recourse to JavaScript as follows:

  1. Select Insert | Chart from the menu.
  2. Double-click the chart, and in the chart editor select Chart Type | Line chart.
  3. Click the grid icon in the "Data range" box to get the data range dialog.
  4. Click the worksheet containing the data you're interested in for the Y-axis lines and highlight from the top left to the bottom right so you cover all the Y-axis lines. You can tidy up the columns later.
  5. Click OK and you'll see a collection of series has been extracted. Use the "dot menu" for each series to remove those you're not interested in.
  6. Click the grid icon in the "X-axis" box to the get the data range dialog once again.
  7. Click the worksheet containing the data you're interested in for the X-axis line and highlight from the top to the bottom.
  8. Click OK and you'll see the X-axis has been filled in and both Y-axis lines are sharing the same left axis label.
  9. Click on the line you want to use the right axis label for and use the "Axis" box in the chart editor dialog to select "Right axis".

You can now edit the various other properties of the chart to get it to look the way you want in terms of presentation.

ゃ懵逼小萝莉 2024-12-09 10:00:13

我做到了。

  1. 单击数据系列
  2. 将出现一个小框,其中包含 2 个小方块,每个小方块只有两个粗体边
  3. 单击第二个

即可完成。

I did it.

  1. Click on the data series
  2. A small box will appear with 2 small squares with only two bold sides each
  3. Click on the second one

Might be done then.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文