简体   繁体   English

我可以在 Google 图表中自定义 Y 轴断点吗?

[英]Can I customize the Y-axis breakpoints in Google Charts?

Here's what my graph look like:这是我的图表的样子:

图形

My client wants the blue line to come closer to the other lines.我的客户希望蓝线更靠近其他线。 Unfortunately, I've been searching for the solution for a couple days and all I got are how to change the min/max value and how to customize the ticks.不幸的是,我几天来一直在寻找解决方案,我得到的只是如何更改最小/最大值以及如何自定义刻度。 So I was wondering if it's possible to do so?所以我想知道是否有可能这样做? If not, are there any alternatives?如果没有,是否有任何替代方案?

Ps.附言。 I found a similar question posted seven years ago, not sure if it's possible now.我在七年前发现了一个类似的问题,不确定现在是否可能。

you can draw the blue line on a secondary y-axis.您可以在辅助 y 轴上绘制蓝线。

depending on which series the blue line represents in the data table,取决于蓝线在数据表中代表的系列,
use the following option to indicate it should be drawn on a separate y-axis.使用以下选项指示它应该绘制在单独的 y 轴上。
where the default y-axis is 0, and the secondary y-axis is 1.其中默认 y 轴为 0,辅助 y 轴为 1。

series: {
  0: {  // <-- series index
    targetAxisIndex: 1  // <-- y-axis index
  }
}

here, the blue line is the first series, 0.在这里,蓝线是第一个系列,0。
see following working snippet...请参阅以下工作片段...

 google.charts.load('current', { packages: ['corechart'] }).then(function () { var data = google.visualization.arrayToDataTable([ ['x', 'y0', 'y1', 'y2'], ['Jan', 33000, 16000, 15000], ['Feb', 41000, 14000, 16000], ['Mar', 43000, 12000, 18000], ['Apr', 39000, 10000, 17000], ['May', 38000, 11000, 16000], ['Jun', 36000, 12000, 14000], ['Jul', 35000, 13000, 12000] ]); var options = { legend: 'none', curveType: 'function', series: { 0: { targetAxisIndex: 1 } } }; var chart = new google.visualization.LineChart(document.getElementById('chart')); chart.draw(data, options); });
 <script src="https://www.gstatic.com/charts/loader.js"></script> <div id="chart"></div>

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

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