【发布时间】:2019-03-27 18:00:14
【问题描述】:
我在 2.4.0 版本中使用 angular6 和 office highcharts 角度包装器 (https://github.com/highcharts/highcharts-angular)。
除了可以手动放置在图表上的标签之外,一切都运行良好。
我只是无法让他们刷新。
我有一个可以通过后端过滤的图表。当我获得新生成的数据时,我将在 html 中使用的 chartOptions 中的数据更新为角度组件的[options]="chartOptions"。
chartOptions 是从我的默认类中实例化的,如下所示:this.chartOptions = new GraphConfigSeqAtteptedVsAchived().chartOptions;
类如下所示: `import * as Highcharts from 'highcharts';
导出类 GraphConfigSeqAtteptedVsAchived{ 公共图表选项:任何;
constructor(){
this.chartOptions = {
chart: {
height: 600,
width: 620,
events:{load: function(){
this.myTooltip = new Highcharts.Tooltip(this, this.options.tooltip);
}
},
backgroundColor: 'transparent',
},
credits: {
text: 'charname',
href: ''
},
labels: {
},
exporting:{
chartOptions:{
title: {
text:'not set',
style:{
color: '#000000'
},
margin: 0
}
}
},
tooltip: {
enabled: false
},
xAxis: {
min: -10,
max: 0,
width: 535,
title: {
text: 'Rainfall (mm)',
style: {
fontWeight: "bold",
color: '#000000'
}
},
reversed: true,
tickInterval: 1
},
yAxis: {
min: -10,
max: 0,
title: {
text: 'Rainfall (mm)',
style: {
fontWeight: "bold",
color: '#000000'
}
},
reversed: true,
tickInterval: 1
},
title: {
text: ' as',
margin: 0,
style:{
color: 'transparent'
}
},
legend: {
layout: 'vertical',
align: 'left',
verticalAlign: 'top',
x: 100,
y: 90,
floating: true,
backgroundColor: '#FFFFFF',
borderWidth: 1,
navigation: {
enabled: false
}
},
plotOptions: {
scatter: {
stickyTracking: false,
allowPointSelect: true,
marker: {
radius: 3,
states: {
hover: {
enabled: true,
lineColor: 'rgb(100,100,100)'
}
}
},
tooltip: {
headerFormat: '<b>{series.name}</b><br>',
pointFormat: '',
hideDelay: 500
},
symbol: "circle",
events: {
mouseOut: function() {
this.chart.myTooltip.hide();
this.chart.myTooltip.options.enabled = false;
},
mouseOver: function() {
if(this.halo) {
this.halo.attr({
'class': 'highcharts-tracker'
}).toFront();
}
},
click: function(event) {
this.chart.myTooltip.options.enabled = true;
this.chart.myTooltip.refresh(event.point, event);
}
}
},
line:{
events: {
legendItemClick: function () {
return false;
}
}
},
series:{
allowPointSelect: true
}
},
series: [{
type: 'line',
data: [[30, 30], [-30, -30]],
marker: {
enabled: false
},
states: {
hover: {
lineWidth: 1
}
},
showInLegend: false,
color: "rgba(0, 0, 0, 0.6)",
enableMouseTracking: false
},{
type: 'line',
data: [[30, 29.5], [-29.5, -30]],
marker: {
enabled: false
},
states: {
hover: {
lineWidth: 0
}
},
showInLegend: false,
dashStyle: 'ShortDash',
color: "rgba(125, 162, 159, 0.35)",
enableMouseTracking: false
},{
type: 'line',
data: [[29.5, 30], [-30, -29.5]],
marker: {
enabled: false
},
states: {
hover: {
lineWidth: 0
}
},
showInLegend: false,
dashStyle: 'ShortDash',
color: "rgba(125, 162, 159, 0.35)",
enableMouseTracking: false
},{
type: 'line',
data: [[29, 30], [-30, -29]],
marker: {
enabled: false
},
states: {
hover: {
lineWidth: 0
}
},
showInLegend: false,
dashStyle: 'ShortDash',
color: "rgba(197, 144, 161, 0.35)",
enableMouseTracking: false
},{
type: 'line',
data: [[30, 29], [-29, -30]],
marker: {
enabled: false
},
states: {
hover: {
lineWidth: 0
}
},
showInLegend: false,
dashStyle: 'ShortDash',
color: "rgba(197, 144, 161, 0.35)",
enableMouseTracking: false
}]
}
}
}`
生成的数据在打字稿中动态添加,所有这些都可以正常工作。在我为 [(update)]="updateGraph" 设置 updateFlag 后,一切都被刷新了。轴标题也很好。
对我来说唯一没有刷新的是我动态添加到图表中的标签,如下所示:
let labelTotalNumberOfEyes = {
html : this.translate.instant('GRAPHS.TOTAL_NUMBER_OF_EYES') + ': ' + (scatterSeries.data.length + scatterSeriesRetreatment.data.length),
style : {
left : '330px',
top : '368px',
fontSize : '14px',
backgroundColor: '#FFFFFF',
borderWidth: 1,
}
}
this.chartOptions.labels.items.push(labelTotalNumberOfEyes);
有人知道我做错了什么吗?除了设置此更新标志之外,我没有看到任何其他选项,它适用于除标签之外的所有内容。
如果您遗漏任何信息,请告诉我。
提前致谢。
【问题讨论】:
-
chart.redraw()? -
不幸的是,角度包装器没有该选项。他们为它实现了一个更新标志,但这似乎只适用于系列和轴。因此,chart.redraw() 不是此设置中的选项。
-
你能在在线代码编辑器(如代码沙盒或 stackblitz)中以某种方式重现它吗?您可以将此演示用作模板:codesandbox.io/s/543l0p0qq4.
-
感谢您精心准备的模板@WojciechChmiel。我调整了模板,只添加了一个标签并在 update char 函数中编辑了文本。您可以看到标签没有更改,但其余部分都没有更改。这正是我遇到的问题。这是我修改后的版本codesandbox.io/s/l22jr69wjq
标签: javascript angular highcharts