Вы можете достичь этого с помощью series.pie.point.events.click
обратного вызова, когда у вас есть доступ к точке, по которой вы щелкнули. Там вы найдете индекс этой точки и индекс диаграммы, который позволяет вам вызывать метод select
в точке с тем же индексом из второго графика. Проверьте код и демоверсию, размещенную ниже. Он использует highcharts-angular официальную упаковку , которую я рекомендую вам использовать (можно скачать здесь: https://github.com/highcharts/highcharts-angular).
app.module.ts:
import { BrowserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";
import { HighchartsChartModule } from "highcharts-angular";
import { ChartComponent } from "./chart.component";
import { AppComponent } from "./app.component";
@NgModule({
declarations: [AppComponent, ChartComponent],
imports: [BrowserModule, HighchartsChartModule],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
chart.component.html:
<div class="boxChart__container">
<div>
<highcharts-chart
id="container"
[Highcharts]="Highcharts"
[constructorType]="chartConstructor"
[options]="chartOptions"
[callbackFunction]="chartCallback"
[(update)]="updateFromInput"
[oneToOne]="true"
style="width: 100%; height: 400px; display: block;"
>
</highcharts-chart>
<highcharts-chart
id="container"
[Highcharts]="Highcharts"
[constructorType]="chartConstructor"
[options]="chartOptions"
[callbackFunction]="chartCallback"
[(update)]="updateFromInput"
[oneToOne]="true"
style="width: 100%; height: 400px; display: block;"
>
</highcharts-chart>
</div>
</div>
chart.component.ts:
import { Component, OnInit } from "@angular/core";
import * as Highcharts from "highcharts";
import * as HighchartsMore from "highcharts/highcharts-more";
import * as HighchartsExporting from "highcharts/modules/exporting";
HighchartsMore(Highcharts);
HighchartsExporting(Highcharts);
@Component({
selector: "app-chart",
templateUrl: "./chart.component.html"
})
export class ChartComponent implements OnInit {
title = "app";
chart;
charts;
updateFromInput = false;
Highcharts = Highcharts;
chartConstructor = "chart";
chartCallback;
chartOptions = {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: "pie"
},
title: {
text: "Browser market shares in January, 2018"
},
tooltip: {
pointFormat: "{series.name}: <b>{point.percentage:.1f}%</b>"
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: "pointer",
dataLabels: {
enabled: true,
format: "<b>{point.name}</b>: {point.percentage:.1f} %",
style: {
color:
(Highcharts.theme && Highcharts.theme.contrastTextColor) ||
"black"
}
}
}
},
series: [
{
name: "Brands",
colorByPoint: true,
point: {
events: {
click: function() {
this.series.chart.chartComponent.showCharts(this);
}
}
},
data: [
{
name: "Chrome",
y: 61.41,
sliced: true,
selected: true
},
{
name: "Internet Explorer",
y: 11.84
},
{
name: "Firefox",
y: 10.85
},
{
name: "Edge",
y: 4.67
},
{
name: "Safari",
y: 4.18
},
{
name: "Sogou Explorer",
y: 1.64
},
{
name: "Opera",
y: 1.6
},
{
name: "QQ",
y: 1.2
},
{
name: "Other",
y: 2.61
}
]
}
]
};
constructor() {
const self = this;
self.chartCallback = chart => {
self.chart = chart;
self.chart.chartComponent = self;
self.charts = Highcharts.charts;
};
}
showCharts(point) {
const chart = point.series.chart,
chartIndex = chart.index,
pointIndex = point.index,
secondChartIndex = chartIndex === 0 ? 1 : 0,
secondChart = this.charts[secondChartIndex],
secondChartPoint = secondChart.series[0].points[pointIndex];
secondChartPoint.select();
}
ngOnInit() {}
}
Демо:
https://codesandbox.io/s/nw8yq0n9ol
Справочник по API:
https://api.highcharts.com/highcharts/series.pie.point.events.click
https://api.highcharts.com/class-reference/Highcharts.Point#select