【问题标题】:AmCharts 4 : Show totals of clustered and stacked charts, for individual clustersAmCharts 4 : 显示单个集群的集群和堆叠图表的总数
【发布时间】:2020-10-09 10:02:46
【问题描述】:

背景:
按照here 所示的堆叠和聚集图表示例,我创建了一个带有聚集和堆叠列的图表。我还尝试在列顶部显示各个堆栈的总数,如here

所示

面临的问题:
我面临的主要问题是显示 ValueAxis 中所有数据的总值,而不是单个堆栈的总值。请帮助显示聚集列的各个总计。

示例代码:
注意用于计算和显示总数的内置 API

// 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 的其他帮助:
找到了在堆叠图表上显示总数的示例,但无法找到处理分组的帮助

【问题讨论】:

    标签: amcharts amcharts4


    【解决方案1】:

    虽然这已经 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 也是如此

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-27
      • 1970-01-01
      • 2019-07-11
      • 2023-03-19
      • 2011-02-23
      相关资源
      最近更新 更多