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 @@ - + 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 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; } + /// /// 获得/设置 是否显示柱状图数据值 ///