我正在使用带角度的图表。
我包含的包裹
"highcharts": "^8.0.4",
"highcharts-angular": "^2.4.0"
进口ts
import * as Highcharts from "highcharts";
HTML上的标记
<highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions">
</highcharts-chart>
这就是我设置chartOptions的方式
private _setChartData(): void {
let _seriesData: Highcharts.PointOptionsObject[];
let _categories: any[];
_seriesData = this._getSeriesData();
_categories = _seriesData.map((_series) => _series.name);
this.chartOptions = {
chart: {
type: "column"
},
title: {
style: { display: "none" }
},
credits: {
enabled: false
},
xAxis: {
crosshair: true,
categories: _categories
},
yAxis: {
min: 0,
title: {
text: "Production Count"
}
},
tooltip: {
headerFormat: `<span style="font-size:10px">{point.key}</span><table>`,
pointFormat: `<tr>
<td style="padding:0"><b>{point.y}</b></td>
</tr>`,
footerFormat: "</table>",
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
showInLegend: false, data: _seriesData, type: "column",
events: { click: (data: any) => this._chartEventHandler(data.point.options) }
}]
};
}
这是_getSeriesData
数据
private _getSeriesData(): Highcharts.PointOptionsObject[] {
const data = getData();
const _seriesData: Highcharts.PointOptionsObject[] = [];
data.forEach((_group, index: number) => {
_seriesData.push({
name: _group.name || "Unknown",
y: _group.count,
// selected : index === 1 ? true : false
});
});
return _seriesData;
}
这很好。
我要突出显示选中的栏,直到悬停为止。
有一种方法可以将条形标记为选中,但它只是将条形颜色更改为灰色,我想突出显示效果。
有什么办法吗?
答案 0 :(得分:2)
启用allowPointSelect
选项并在brightness
中使用states.select
属性:
plotOptions: {
column: {
...,
allowPointSelect: true,
states: {
select: {
color: '',
brightness: 0.1
}
}
}
}
实时演示: http://jsfiddle.net/BlackLabel/6m4e8x0y/5008/
API参考:
https://api.highcharts.com/highcharts/series.column.states.select
https://api.highcharts.com/highcharts/series.column.allowPointSelect