Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>10.0.5</Version>
<Version>10.0.6</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,39 @@ const getChartOption = function (option) {
showDataLabel = context => Number(context.dataset?.data[context.dataIndex]) !== 0;
}

const datalabels = {
anchor: option.options.anchor,
align: option.options.align,
formatter: option.options.formatter,
display: showDataLabel,
color: option.options.chartDataLabelColor,
font: {
weight: 'bold'
}
};

if (option.options.showTotalDataLabel && option.options.x.stacked) {
const lastVisibleIndex = chart => {
let last = -1;
chart.data.datasets.forEach((v, index) => {
if (chart.isDatasetVisible(index)) {
last = index;
}
});
return last;
};
datalabels.labels = {
value: {},
total: {
anchor: 'end',
align: 'end',
display: context => context.datasetIndex === lastVisibleIndex(context.chart),
formatter: (value, context) => context.chart.data.datasets.reduce(
(total, v, index) => context.chart.isDatasetVisible(index) ? total + (Number(v.data[context.dataIndex]) || 0) : total, 0)
}
};
}

return {
...config,
...{
Expand All @@ -412,16 +445,7 @@ const getChartOption = function (option) {
display: option.options.title != null,
text: option.options.title
},
datalabels: {
anchor: option.options.anchor,
align: option.options.align,
formatter: option.options.formatter,
display: showDataLabel,
color: option.options.chartDataLabelColor,
font: {
weight: 'bold'
}
},
datalabels: datalabels,
customCanvasBackgroundColor: {
color: option.options.canvasBackgroundColor,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ public class ChartOptions
/// </summary>
public bool ShowDataLabel { get; set; }

/// <summary>
/// 获得/设置 堆叠模式下是否在每个柱条顶部显示总计数据标签 默认 false
/// </summary>
public bool ShowTotalDataLabel { get; set; }

/// <summary>
/// 获得/设置 是否单独设置柱状图颜色
/// </summary>
Expand Down
Loading