From ea7dfcfc2cfbd6aeb9630e7986d4c4c222bea996 Mon Sep 17 00:00:00 2001 From: lee Date: Thu, 9 May 2024 09:38:52 +0800 Subject: [PATCH 1/3] Add `customCanvasBackgroundColor` plugin to `Chart.razor.js` Added a new plugin named `customCanvasBackgroundColor` to `Chart.razor.js` that allows setting a custom background color for the chart canvas. The `chartOption` object and `getChartOption` function were updated to include this new plugin. Also, a new property `CanvasBackgroundColor` was added to the `ChartOptions` class in `ChartOptions.cs` to get or set the background color of the chart canvas. --- .../Components/Chart/Chart.razor.js | 20 ++++++++++++++++++- .../Components/Chart/ChartOptions.cs | 5 +++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Extensions/Components/BootstrapBlazor.Chart/Components/Chart/Chart.razor.js b/src/Extensions/Components/BootstrapBlazor.Chart/Components/Chart/Chart.razor.js index 29cc084cdbd..3923b93dcad 100644 --- a/src/Extensions/Components/BootstrapBlazor.Chart/Components/Chart/Chart.razor.js +++ b/src/Extensions/Components/BootstrapBlazor.Chart/Components/Chart/Chart.razor.js @@ -5,6 +5,20 @@ import EventHandler from "../../../BootstrapBlazor/modules/event-handler.js" Chart.register(ChartDataLabels); +const plugin = { + id: 'customCanvasBackgroundColor', + beforeDraw: (chart, args, options) => { + if (options.color) { + const { ctx } = chart; + ctx.save(); + ctx.globalCompositeOperation = 'destination-over'; + ctx.fillStyle = options.color; + ctx.fillRect(0, 0, chart.width, chart.height); + ctx.restore(); + } + } +}; + const chartOption = { options: { responsive: true, @@ -41,7 +55,8 @@ const chartOption = { } } } - } + }, + plugins: [plugin] } const skipped = (ctx, value) => ctx.p0.skip || ctx.p1.skip ? value : undefined @@ -315,6 +330,9 @@ const getChartOption = function (option) { font: { weight: 'bold' } + }, + customCanvasBackgroundColor: { + color: option.options.canvasBackgroundColor, } }, scales: scale diff --git a/src/Extensions/Components/BootstrapBlazor.Chart/Components/Chart/ChartOptions.cs b/src/Extensions/Components/BootstrapBlazor.Chart/Components/Chart/ChartOptions.cs index 3ec843007af..861430d9efa 100644 --- a/src/Extensions/Components/BootstrapBlazor.Chart/Components/Chart/ChartOptions.cs +++ b/src/Extensions/Components/BootstrapBlazor.Chart/Components/Chart/ChartOptions.cs @@ -159,6 +159,11 @@ public class ChartOptions /// public string? YScalesGridTickColor { get; set; } + /// + /// 获得/设置 图表背景颜色 + /// + public string? CanvasBackgroundColor { get; set; } + /// /// 获得/设置 是否显示柱状图数据值 /// From 80ed2ae54bb03dd5e9ff13638fae243a98118812 Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Thu, 9 May 2024 10:37:21 +0800 Subject: [PATCH 2/3] chore: bump version 8.1.3 --- .../BootstrapBlazor.Chart/BootstrapBlazor.Chart.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Extensions/Components/BootstrapBlazor.Chart/BootstrapBlazor.Chart.csproj b/src/Extensions/Components/BootstrapBlazor.Chart/BootstrapBlazor.Chart.csproj index 957e773e077..06717891003 100644 --- a/src/Extensions/Components/BootstrapBlazor.Chart/BootstrapBlazor.Chart.csproj +++ b/src/Extensions/Components/BootstrapBlazor.Chart/BootstrapBlazor.Chart.csproj @@ -1,7 +1,7 @@ - 8.1.2 + 8.1.3 Bootstrap Blazor WebAssembly wasm UI Components Chart Bootstrap UI components extensions of Chart.js From 94bc57bf8eecbace1057e83f7776a4755ec4a1cf Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Thu, 9 May 2024 12:27:56 +0800 Subject: [PATCH 3/3] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj b/src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj index 8cbcd0fa8df..fe0dcfaf3a6 100644 --- a/src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj +++ b/src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj @@ -34,7 +34,7 @@ - +