简体   繁体   English

AmCharts Legend,如何在图表中的数据更改上重新单击未单击的图例

[英]AmCharts Legend, How to reclick an unclicked legend on Data changes in the chart

I have a divergent stacked bar chart from Am charts that I have built custom filters for, the filters change the data by replacing the entire amChart.data with a new preprepared JSON data.我有一个来自 Am 图表的发散堆积条形图,我为其构建了自定义过滤器,过滤器通过用新的准备好的 JSON 数据替换整个 amChart.data 来更改数据。 I'm using Angular 8 with typescript and no backend, the JSON data are saved in the assets and loaded by a service then passed on to the chart.我正在使用带有打字稿且没有后端的 Angular 8,JSON 数据保存在资产中并由服务加载,然后传递到图表。

These are the relevant code snippets, unfortantly I am not alowed to share the entire code.这些是相关的代码片段,不幸的是我不能分享整个代码。

 @Input() dataToDisplay: EventEmitter<any>;

 private amChart: any;

constructor(private wh: WarehouseService) {}

ngOnInit() {
 this.currentYearDisplayed.subscribe(async year => {
  await this.wh.loadData(year);
  this.loadDataIntoChart();
});
this.dataToDisplay.subscribe(data => {
  if (this.amChart) {
    this.amChart.data = data;
    this.amChart.invalidateData();
  }
});

} }

  loadDataIntoChart() {
    if (this.amChart) {
      this.amChart.data = this.wh.filteredSet;
    }
  }

The initial chart looks like this初始图表如下所示

I unclick the Legend Aufwand, the dark blue line disapear.我取消单击 Legend Aufwand,深蓝色线条消失。 I click on a filter that changes the data and reloads (while the Aufwand Legend is still uncklicked)我点击了一个改变数据并重新加载的过滤器(而 Aufwand Legend 仍然没有被点击)

Chart then looks like this图表看起来像这样

My Legend code is我的传奇代码是

   // Legend
    this.amChart.legend = new am4charts.Legend();
    this.amChart.legend.position = "right";
    this.amChart.legend.width = 100;

What I have been trying to do, is simply reclick all inactive legends on data change before loading the data, I couldn't find proper setting in the documintation or here in stackoverflow.我一直在尝试做的,只是在加载数据之前重新单击数据更改上的所有非活动图例,我在文档中或在 stackoverflow 中找不到正确的设置。

Any help is appreciated and thank you in advance.任何帮助表示赞赏,并提前感谢您。

You can unhide hidden series via API by calling show() method on its object.您可以通过 API 对其对象调用show()方法来取消隐藏隐藏系列。

The following will unhide all series:以下将取消隐藏所有系列:

this.amChart.series.each(function(series) {
  series.show();
});

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

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