我的页面上显示了一个 ng2-chart 条形图,但我正在寻找该条的值,例如 5, 7, 9 。
我可以获得标签名称......但无法获得价值。
有没有人这样做过?
public chartClicked(e:any):void {
//e.active[0]._model.label gives the label.
console.log(e);
}
我的页面上显示了一个 ng2-chart 条形图,但我正在寻找该条的值,例如 5, 7, 9 。
我可以获得标签名称......但无法获得价值。
有没有人这样做过?
public chartClicked(e:any):void {
//e.active[0]._model.label gives the label.
console.log(e);
}
您可以使用此解决方案:
lineChartData:你的数据源是从你的 中填充的API
,所以你必须添加你点击时会用到的必要数据。
public chartClicked(e: any): void {
if (e.active.length > 0) {
const chart = e.active[0]._chart;
const activePoints = chart.getElementAtEvent(e.event);
if ( activePoints.length > 0) {
const clickedElementIndex = activePoints[0]._index;
const label = chart.data.labels[clickedElementIndex];
console.log("serie from your dataset = " + activePoints[0]._model.datasetLabel);
console.log("dataset index = " + activePoints[0]._datasetIndex);
console.log("serie id from your data source = " + this.lineChartData[activePoints[0]._datasetIndex].labelId);
console.log("serie from your data source = " + this.lineChartData[activePoints[0]._datasetIndex].label);
console.log("label from your dataset = " + label);
}
}}
你可以试试这个:
e.active[0]._chart.tooltip._model.dataPoints[0].yLabel