问题描述
背景:
按照here所示的堆积图和聚簇图示例,我创建了一个包含聚簇和堆积列的图表。我还尝试在列顶部显示各个堆栈的总数,如图here
面临的问题:
我要面对的主要问题是显示ValueAxis中所有数据的总值,而不是单个堆栈的总值。请帮助显示各个汇总列的总计。
// Fully working example in the CodePen
// Enabling totals calculation
let valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
valueAxis.calculatetotals = true;
// displaying the total in the LabelBullet
let totalBullet = totalSeries.bullets.push(new am4charts.LabelBullet());
totalBullet.label.text = "{valueY.sum}";
Codepen depicting the issue (请注意堆积列顶部的总数)
已考虑的替代方法:
StackOverflow的其他帮助:
找到了在堆叠图表上显示总计的样本,但无法找到有关分组的帮助
解决方法
虽然这是 7 个月大,但我也没有在任何地方找到答案。如果您还没有找到解决方案,我可以通过创建两个 Y 轴并分别为它们分配系列来解决此问题,然后也为总计项目符号添加“无”系列。
我在 jsfiddle 中修改了您的 Codepen 示例 here(由于某些原因,codepen 对我来说冻结了)
基本上,尽管您创建了两个轴,并隐藏了第二个轴的标签。
let valueAxis0 = chart.yAxes.push(new am4charts.ValueAxis());
valueAxis0.min = 0;
valueAxis0.calculateTotals = true;
valueAxis0.title.text = "Expenditure (M)";
var valueAxis1 = chart.yAxes.push(new am4charts.ValueAxis());
valueAxis1.renderer.grid.template.disabled = true;
valueAxis1.calculateTotals = true;
valueAxis1.syncWithAxis = chart.yAxes.getIndex(0);
valueAxis1.min = 0;
valueAxis1.renderer.labels.template.disabled = true;
然后在创建系列时选择它并使用 series.yAxis = valueAxis;
function createSeries(field,name,stacked,yAxes) {
var valueAxis;
if (yAxes == 0) {
valueAxis = valueAxis0;
} else if (yAxes == 1) {
valueAxis = valueAxis1;
}
let series = chart.series.push(new am4charts.ColumnSeries());
...
series.yAxis = valueAxis;
TotalSeries 也是如此