Merge branch 'feature/SUPPORT-9206_label_for_each_data' into develop
This commit is contained in:
commit
b1ec308ce5
3 changed files with 31 additions and 20 deletions
|
|
@ -93,6 +93,7 @@ public class RoundSingleChartDataSetService extends AbstractChartDatasetService
|
||||||
List<SingleChartDataSetDto> datasets = new ArrayList<>();
|
List<SingleChartDataSetDto> datasets = new ArrayList<>();
|
||||||
List<ChartLabelModel> centerLabelModels = new ArrayList<>();
|
List<ChartLabelModel> centerLabelModels = new ArrayList<>();
|
||||||
List<Object> labels = new ArrayList<>();
|
List<Object> labels = new ArrayList<>();
|
||||||
|
List<List<Object>> dataLabels = new ArrayList<>();
|
||||||
|
|
||||||
for (Future<RoundChartDataSetDtoWrapper> future : dataSetFutures) {
|
for (Future<RoundChartDataSetDtoWrapper> future : dataSetFutures) {
|
||||||
RoundChartDataSetDtoWrapper chartDataSetDto = future.get();
|
RoundChartDataSetDtoWrapper chartDataSetDto = future.get();
|
||||||
|
|
@ -101,6 +102,7 @@ public class RoundSingleChartDataSetService extends AbstractChartDatasetService
|
||||||
datasets.add(chartDataSetDto.getRoundChartDataSetDto());
|
datasets.add(chartDataSetDto.getRoundChartDataSetDto());
|
||||||
}
|
}
|
||||||
labels.addAll(chartDataSetDto.getLabels());
|
labels.addAll(chartDataSetDto.getLabels());
|
||||||
|
dataLabels.add(chartDataSetDto.getLabels());
|
||||||
}
|
}
|
||||||
executorService.shutdown();
|
executorService.shutdown();
|
||||||
|
|
||||||
|
|
@ -108,7 +110,7 @@ public class RoundSingleChartDataSetService extends AbstractChartDatasetService
|
||||||
centerLabelModels.add(future.get());
|
centerLabelModels.add(future.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RoundChartDataDto(datasets, labels, centerLabelModels);
|
return new RoundChartDataDto(datasets, labels, centerLabelModels, dataLabels);
|
||||||
}
|
}
|
||||||
catch (InterruptedException | ExecutionException e) {
|
catch (InterruptedException | ExecutionException e) {
|
||||||
executorService.shutdownNow();
|
executorService.shutdownNow();
|
||||||
|
|
|
||||||
|
|
@ -12,22 +12,16 @@ import ervu_business_metrics.model.chart.round.label.ChartLabelModel;
|
||||||
public class RoundChartDataDto extends SingleChartDataDto {
|
public class RoundChartDataDto extends SingleChartDataDto {
|
||||||
|
|
||||||
public List<ChartLabelModel> centerLabels;
|
public List<ChartLabelModel> centerLabels;
|
||||||
|
public List<List<Object>> dataLabels;
|
||||||
|
|
||||||
public RoundChartDataDto(
|
public RoundChartDataDto(
|
||||||
List<SingleChartDataSetDto> datasets,
|
List<SingleChartDataSetDto> datasets,
|
||||||
List<Object> labels,
|
List<Object> labels,
|
||||||
List<ChartLabelModel> centerLabels
|
List<ChartLabelModel> centerLabels,
|
||||||
|
List<List<Object>> dataLabels
|
||||||
) {
|
) {
|
||||||
super(datasets, labels);
|
super(datasets, labels);
|
||||||
this.centerLabels = centerLabels;
|
this.centerLabels = centerLabels;
|
||||||
}
|
this.dataLabels = dataLabels;
|
||||||
|
|
||||||
public List<ChartLabelModel> getCenterLabels() {
|
|
||||||
return centerLabels;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCenterLabels(
|
|
||||||
List<ChartLabelModel> centerLabels) {
|
|
||||||
this.centerLabels = centerLabels;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -224,6 +224,7 @@ export class ErvuChartV2 extends Control implements Filterable {
|
||||||
chartOptions.plugins = chartOptions.plugins ? chartOptions.plugins : {};
|
chartOptions.plugins = chartOptions.plugins ? chartOptions.plugins : {};
|
||||||
|
|
||||||
chartOptions.plugins.legend = this.legend ? this.legend : {};
|
chartOptions.plugins.legend = this.legend ? this.legend : {};
|
||||||
|
|
||||||
chartOptions.plugins.tooltip = {
|
chartOptions.plugins.tooltip = {
|
||||||
enabled: false, //Disables default tooltip from charjs (we'll use a custom tooltip)
|
enabled: false, //Disables default tooltip from charjs (we'll use a custom tooltip)
|
||||||
external: (context) => {
|
external: (context) => {
|
||||||
|
|
@ -245,12 +246,35 @@ export class ErvuChartV2 extends Control implements Filterable {
|
||||||
filter: tooltipItem => {
|
filter: tooltipItem => {
|
||||||
const type = tooltipItem.chart.config.type;
|
const type = tooltipItem.chart.config.type;
|
||||||
if (type == 'doughnut' || type == 'pie') {
|
if (type == 'doughnut' || type == 'pie') {
|
||||||
|
const dataLabels = tooltipItem.chart.config.data.dataLabels;
|
||||||
|
if (dataLabels) {
|
||||||
|
const dataLabel = dataLabels[tooltipItem.datasetIndex][tooltipItem.dataIndex];
|
||||||
|
if (dataLabel) {
|
||||||
|
tooltipItem.label = dataLabel;
|
||||||
|
}
|
||||||
|
}
|
||||||
return tooltipItem.label.trim().length !== 0;
|
return tooltipItem.label.trim().length !== 0;
|
||||||
}
|
}
|
||||||
return tooltipItem.dataset.label.trim().length !== 0;
|
return tooltipItem.dataset.label.trim().length !== 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
chartOptions.plugins.tooltip.callbacks = {
|
||||||
|
label: function (tooltipItem) {
|
||||||
|
const dataset = tooltipItem.dataset;
|
||||||
|
if (dataset.type == 'bar' || dataset.type == 'line') {
|
||||||
|
return dataset.label + ' : ' + dataset.data[tooltipItem.dataIndex].x.toLocaleString();
|
||||||
|
}
|
||||||
|
let dataLabel;
|
||||||
|
const dataLabels = tooltipItem.chart.config.data.dataLabels;
|
||||||
|
if (dataLabels) {
|
||||||
|
dataLabel = dataLabels[tooltipItem.datasetIndex][tooltipItem.dataIndex];
|
||||||
|
}
|
||||||
|
return dataLabel ? dataLabel : tooltipItem.label + ' : ' +
|
||||||
|
dataset.data[tooltipItem.dataIndex].toLocaleString();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (this.title && this.title.text) {
|
if (this.title && this.title.text) {
|
||||||
chartOptions.plugins.title = this.title;
|
chartOptions.plugins.title = this.title;
|
||||||
}
|
}
|
||||||
|
|
@ -338,15 +362,6 @@ export class ErvuChartV2 extends Control implements Filterable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
chartConfig.options.plugins.tooltip.callbacks = {
|
|
||||||
label: function (tooltipItem) {
|
|
||||||
const dataset = tooltipItem.dataset;
|
|
||||||
if (dataset.type == 'bar' || dataset.type == 'line') {
|
|
||||||
return dataset.label + ' : ' + dataset.data[tooltipItem.dataIndex].x.toLocaleString();
|
|
||||||
}
|
|
||||||
return tooltipItem.label + ' : ' + dataset.data[tooltipItem.dataIndex].toLocaleString();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.chartConfig = chartConfig;
|
this.chartConfig = chartConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue