当数据少于 3 个值时,AMCharts 系列不出现的问题

Issue with AMCharts Series not appearing when The data has less than 3 values

我在 WordPress 项目中使用 AMCharts4,一切正常,但我在过滤数据时遇到了一个奇怪的问题,让我展示一下图像发生了什么:

-过滤数据(超过 2 个结果 100%)

查看前两张图片如何不显示各自的分数。

这里的问题是如何显示这些分数?我在我的函数中尝试了注释代码行,但似乎没有任何效果。

您可以在此 link 中重现该问题,例如选择澳大利亚或巴西位置

看看我的函数here

labelBullet = series.bullets.push(new am4charts.LabelBullet())
labelBullet.label.horizontalCenter = "left";
labelBullet.label.dx = 10;
labelBullet.label.text = "{values.valueX.workingValue.formatNumber('#.')}";
labelBullet.locationX = 1;

问题出在您对 labelBullet.locationX = 1; 的使用上。如果你看一下 am4 Bullets documentation:

There's one caveat, though. For bullets, locationY property means the relative vertical position in the whole height of the column. That means that if our scale would not start at zero, it would be not in the direct center of the currently visible portion of the column.

当您使用倒置图表时,同样适用于您的情况 locationX。意思是,标签位置是相对于比例尺的。

要解决此问题,您可以将值轴的 min 设置为 0,如此 jsfiddle 使用:

valueAxis.min = 0;

或者如文档中所述,将标签直接推送到列系列模板中,如此 jsfiddle.

label = series.columns.template.createChild(am4core.Label);
label.text = "{values.valueX.workingValue.formatNumber('#.')}";
label.align = "left";
label.valign = "middle";
label.zIndex = 2;