Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Chart): LineChart BorderWidth Property settings are not valid #936

Merged
merged 3 commits into from
Apr 1, 2023
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
Expand Up @@ -2,7 +2,7 @@
@using Utility = BootstrapBlazor.Shared.Samples.Charts.Utility
@inject IStringLocalizer<Line> Localizer

<Chart @ref="LineChart" OnInitAsync="() => OnInit(0.4f, false)" OnAfterInitAsync="@OnAfterInit" OnAfterUpdateAsync="@OnAfterUpdate" />
<Chart @ref="LineChart" BorderWidth="1" OnInitAsync="() => OnInit(0.4f, false)" OnAfterInitAsync="@OnAfterInit" OnAfterUpdateAsync="@OnAfterUpdate" />
<div class="text-center mt-2 chart">
<div class="btn-group">
<button class="btn btn-primary" @onclick="e => Utility.RandomData(LineChart)"><i class="fa-solid fa-chart-line"></i><span>@Localizer["LineOnInitRandomData"]</span></button>
Expand Down Expand Up @@ -56,6 +56,7 @@
ds.Options.Title = "Line Chart";
ds.Options.X.Title = "days";
ds.Options.Y.Title = "Numerical value";
ds.Options.BorderWidth = Randomer.Next(1, 5);//设置折线图线宽,Options.BorderWidth优先级高于组件上设置的BorderWidth="1"
ds.Labels = Enumerable.Range(1, LineDataCount).Select(i => i.ToString());
for (var index = 0; index < LineDatasetCount; index++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor.Shared/Locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@
},
"BootstrapBlazor.Shared.Samples.Charts.Line": {
"LineOnInitTitle": "Line graph",
"LineOnInitIntro": "Use <code>OnInit</code> to call back the delegate method, and after assigning the initialization data, the drawing operation can be performed",
"LineOnInitIntro": "Use <code>OnInit</code> to call back the delegate method, and after assigning the initialization data, the drawing operation can be performed, By setting the <code>BorderWidth</code> attribute, you can set the line width of the line chart, with a default value of 3",
"LineOnInitRandomData": "Random data",
"LineOnInitAddDataset": "Add dataset",
"LineOnInitRemoveDataset": "Remove dataset",
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor.Shared/Locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@
},
"BootstrapBlazor.Shared.Samples.Charts.Line": {
"LineOnInitTitle": "Line 图",
"LineOnInitIntro": "使用 <code>OnInit</code> 回调委托方法,对初始化数据进行赋值后,即可进行绘图操作",
"LineOnInitIntro": "使用 <code>OnInit</code> 回调委托方法,对初始化数据进行赋值后,即可进行绘图操作,通过设置 <code>BorderWidth</code> 属性,可以设置折线图线宽,默认值3。",
"LineOnInitRandomData": "随机数据",
"LineOnInitAddDataset": "添加数据集",
"LineOnInitRemoveDataset": "移除数据集",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public partial class Chart : BootstrapComponentBase, IDisposable
/// 获得/设置 Line 折线图线的宽度
/// </summary>
[Parameter]
public double BorderWidth { get; set; } = 3;
public double BorderWidth { get; set; }

/// <summary>
/// 获得/设置 正在加载文本
Expand Down Expand Up @@ -201,7 +201,6 @@ public async Task Update(ChartAction action)
}
}


/// <summary>
/// 重新加载方法, 强制重新渲染图表
/// </summary>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function ($) {
window.chartOption = {
options: {
borderWidth:3,
borderWidth: 3,
responsive: true,
maintainAspectRatio: true,
aspectRatio: 2,
Expand Down Expand Up @@ -74,6 +74,9 @@
});
option.options = $.extend(true, option.options, genericOptions);
}
if (option.options.borderWidth > 0) {
chartOption.options.borderWidth = option.options.borderWidth;
}
config = $.extend(true, {}, chartOption);
colorFunc = function (data) {
var color = chartColors[colors.shift()]
Expand Down Expand Up @@ -266,7 +269,7 @@
if (option.options.height !== null) {
chart.canvas.parentNode.style.height = option.options.height;
}
if (option.options.width !== null) {
if (option.options.width !== null) {
chart.canvas.parentNode.style.width = option.options.width;
}
$el.removeClass('is-loading').trigger('chart.afterInit');
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.