amCharts 4 - 如何使图表宽度与不同长度的ValueAxis标签相等

问题描述 投票:2回答:1

在至少amCharts 4中,图表宽度似乎取决于valueAxis标签的长度(例如,位数)。例如,在this codepen中获取图表。顶部图表标签设置为精度8,底部图表设置为最多5位数(例如,“10,000”作为最大值),底部图表的宽度可以等于顶部图表的宽度包括以下内容:

valueAxis2.marginLeft = "32px";

但是,如果底部图表的valueAxis标签中的位数发生变化,则左边距不再正确。例如,取消注释第22行以查看此内容。如何使图表宽度与valueAxis标签长度无关?

This answer讨论了amCharts 3的解决方案,但amCharts 4中似乎没有minMarginLeft属性。

amcharts amcharts4
1个回答
1
投票

好问题。我强烈建议您查看我们的Working with Containers guideThe last section illustrates the pre-defined Containers for XYCharts

左侧渲染的任何y轴都位于chart.leftAxesContainer中,因此您可以在每个图表上将它们设置为相同的宽度,例如

// Top chart's left y axis is around 96px (checked via its measuredWidth)
chart1.leftAxesContainer.width = 100;
chart2.leftAxesContainer.width = 100;

这是一个分叉:

https://codepen.io/team/amcharts/pen/a0a990fa6420b446508770ccae40ca7d

截图(不需要播放边距!):

screenshot of charts adjacent to each, their yaxes are the same width

© www.soinside.com 2019 - 2024. All rights reserved.