0

我正在用 Angular2 和 TypeScript 编写 SPA Web App。屏幕的重要部分被 Highcharts 图表区域占据,其中可能有几个完全不同的图表(具有不同的比例、图例等,因此,不同的选项)。所以最初我在那里指定Options1(OptionsDflt),但随后用户可以与应用程序交互,它应该显示Options2或Options3......所以有没有办法改变Options(到目前为止它对我不起作用,我试过setOptions( )、update()、draw() - 不走运)。

或者将每个图表放在面板上并像一堆卡片一样操作是否有意义?

这是我的代码片段,也许会有所帮助。

所以在 Angular2.0 页面模板中,我将 HighCharts 图定义为:

<chart id="linechart" (load)="saveChart($event.context)" [options]="optionsDflt" ></chart>

then in Constructor I define optionsDflt and options1.

optionsDflt : Object; 
options1 : Object; 
chart1 : any; 

saveChart(chart) {
this.chart1 = chart; 
}

onUserClick() { // that is where it should switch to graph defined by options1
// populate options1 series with data from JSON retrieved from DB
// populate xAxis categories 
this.chart1.xAxis[0].setCategories(this.options1.xAxis.categories, true);

// here I try to set options1 in chart1 - but all 3 lines give me that it "is not a function"
this.chart1.update(this.options1);
this.chart1.setOptions(this.options1);
this.chart1.redraw(this.options1);

this.saveChart(this.options1); // tried that also - did not work
}

知道如何将图形设置为 options1 吗?

我在这里做错什么了吗?

我对 Highcharts 很陌生,对 Angular2 也很陌生。

我在将该应用程序从 Angular 2.0.0 升级到 2.4.x 时遇到的另一个问题 - 它使用的是 TypeScript 2.x,它比 1.8 严格得多,所以现在我遇到了很多错误,例如:
Property 'data' does not存在于“对象”类型上。//即来自 RxJS 订阅
或“对象”类型上不存在属性“系列”(或 xAxis) - 好吧,没有类选项或图表,我必须将其定义为对象。如何解决这些错误?等待 Ang2-Highcharts 实现它?

请指教。

TIA,奥列格。

4

0 回答 0