【发布时间】:2021-07-01 05:45:50
【问题描述】:
我在我的 Angular 项目中使用高图表 API,我的问题是当我获得动态数据时,我成功生成了高图表,但是当我点击任何状态时,我的向下钻取功能没有被命中或不工作。在我的场景中需要使用带有钻取的 highchart,因此经过大约 5 个小时的搜索和开发,我没有从谷歌或 highcharts 自己的论坛获得任何解决方案。
这是我的代码:
generateMap() {
this.Highcharts = Highcharts;
const usMapData = require("@highcharts/map-collection/countries/us/us-all.geo.json");
const usMap = Highcharts.geojson(usMapData);
this.chartOptions = {
chart: {
height: (8 / 16) * 100 + "%",
},
events: {
drilldown: function (e) {
this.methodMap(e.point.splitName);
const chart = this as any;
const mapKey = "countries/us/" + e.point.drilldown + "-all";
const mapData = require(`@highcharts/map-collection/${mapKey}.geo.json`);
const provinceData = Highcharts.geojson(mapData);
chart.addSeriesAsDrilldown(e.point, {
name: e.point.name,
data: provinceData,
dataLabels: {
enabled: true,
format: '{point.name}'
}
});
chart.setTitle(null, { text: e.point.name });
},
drillup() {
const chart = this as any;
}
},
title: {
text: ""
},
colorAxis: {
min: 0,
minColor: "#E6E7E8",
maxColor: "#417BCC"
},
mapNavigation: {
enabled: true,
buttonOptions: {
verticalAlign: "bottom"
}
},
plotOptions: {
map: {
states: {
hover: {
color: "#F8BA03"
}
}
},
series: {
point: {
events: {
click: function (e) {
}
}
}
}
},
series: [
{
animation: {
duration: 1000
},
name: "United States",
data: null,
dataLabels: {
enabled: true,
color: '#FFFFFF',
format: `{point.splitName}`,
style: {
textTransform: 'uppercase',
}
},
}
],
drilldown: {}
};
this.CurrentVendorService.getAllVendorStates().pipe(
tap(result => {
this.chart.showLoading();
usMap.forEach((el: any, i) => {
el.splitName = el.properties["hc-key"].split('-')[1].toUpperCase();
el.drilldown = el.properties["hc-key"];
const getFirstMatchedVendor = result.data.find(vendorObj => vendorObj.State_Code == el.splitName);
if (getFirstMatchedVendor) {
el.value = getFirstMatchedVendor.Vendor_Count;
}
});
this.chartOptions.series = [
{
data: usMap
}
];
this.updateFromInput = true;
this.chart.hideLoading();
},
(error: any) => {
this.gifLoader = false
this.errorMessage = error.error.message;
this.snackBar.open(this.errorMessage, '', {
duration: 2000,
});
console.log(`error on retriving all vendors state list : ${error}`);
}
),
finalize(() => {})).subscribe();
}
组件.Html
<highcharts-chart
[Highcharts]="Highcharts"
[constructorType]="chartConstructor"
[callbackFunction]="chartCallback"
[options]="chartOptions"
style="width: 100%; height: 400px; display: block;"
[(update)]="updateFromInput"
></highcharts-chart>
generateMap() 致电ngOnInit()。如果我使用静态数据而不是服务。它的作用就像一个魅力,但这里的情况并非如此。我需要对我的动态数据进行深入研究。请帮我解决我做错的事情。
【问题讨论】:
标签: angular highcharts angular2-highcharts