SUPPORT-9217: add tooltip creation function
This commit is contained in:
parent
741e52922e
commit
2585539291
3 changed files with 28 additions and 7 deletions
|
|
@ -23,6 +23,7 @@ import {ChartBarSettings} from "./model/ChartBarSettings";
|
|||
import {ChartLegendSettings} from "./model/ChartLegendSettings";
|
||||
import {Options} from "./model/Options";
|
||||
import {ChartPlugin} from "./plugin/ChartPlugin";
|
||||
import {DataTooltip} from "./tooltip/DataTooltip";
|
||||
import {ChartUtils} from "./ChartUtils";
|
||||
import {ErvuChartTooltip} from "./ErvuChartTooltip";
|
||||
|
||||
|
|
@ -97,6 +98,8 @@ export class ErvuChartV2 extends Control implements Filterable {
|
|||
public tooltipPosition: any;
|
||||
@Visible("false")
|
||||
public tooltipModel: TooltipModel<any>;
|
||||
@AdvancedProperty()
|
||||
public dataTooltip: DataTooltip;
|
||||
|
||||
private chartRpcService: ChartV2RpcService;
|
||||
private filterMap: { [key: string]: Filter } = {};
|
||||
|
|
@ -259,19 +262,27 @@ export class ErvuChartV2 extends Control implements Filterable {
|
|||
}
|
||||
};
|
||||
|
||||
chartConfig.dataTooltip = this.dataTooltip
|
||||
? this.dataTooltip.tooltip
|
||||
: ((dataLabel, value) => dataLabel + ' : ' + value) ;
|
||||
chartOptions.plugins.tooltip.callbacks = {
|
||||
label: function (tooltipItem) {
|
||||
const dataset = tooltipItem.dataset;
|
||||
let dataLabel: string;
|
||||
let value;
|
||||
if (dataset.type == 'bar' || dataset.type == 'line') {
|
||||
return dataset.label + ' : ' + dataset.data[tooltipItem.dataIndex].x.toLocaleString();
|
||||
dataLabel = dataset.label;
|
||||
value = dataset.data[tooltipItem.dataIndex].x.toLocaleString();
|
||||
}
|
||||
let dataLabel;
|
||||
const dataLabels = tooltipItem.chart.config.data.dataLabels;
|
||||
if (dataLabels) {
|
||||
dataLabel = dataLabels[tooltipItem.datasetIndex][tooltipItem.dataIndex];
|
||||
else {
|
||||
const dataLabels = tooltipItem.chart.config.data.dataLabels;
|
||||
if (dataLabels) {
|
||||
dataLabel = dataLabels[tooltipItem.datasetIndex][tooltipItem.dataIndex];
|
||||
}
|
||||
dataLabel = dataLabel ? dataLabel : tooltipItem.label;
|
||||
value = dataset.data[tooltipItem.dataIndex].toLocaleString();
|
||||
}
|
||||
return dataLabel ? dataLabel : tooltipItem.label + ' : ' +
|
||||
dataset.data[tooltipItem.dataIndex].toLocaleString();
|
||||
return tooltipItem.chart.config.dataTooltip(dataLabel, value);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
export interface DataTooltip {
|
||||
tooltip(dataLabel, value): string;
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import {DataTooltip} from "./DataTooltip";
|
||||
|
||||
export class ValueBeforeDataTooltip implements DataTooltip {
|
||||
tooltip(dataLabel, value): string {
|
||||
return "" + value + " " + dataLabel;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue