Skip to content

Commit d9269e9

Browse files
authored
doc(Bar): add center sample code (#8219)
1 parent d661903 commit d9269e9

4 files changed

Lines changed: 16 additions & 5 deletions

File tree

src/BootstrapBlazor.Server/Components/Samples/Charts/Bar.razor

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@
6060
<DemoBlock Title="@Localizer["BarStackedShowDataLabelTitle"]"
6161
Introduction="@Localizer["BarStackedShowDataLabelIntro"]"
6262
Name="BarStackedShowDataLabel">
63-
<Chart ChartType="ChartType.Bar" OnInitAsync="OnInitStackedShowDataLabel" Height="500px" Width="500px" />
63+
<div class="row">
64+
<div class="col-12 col-sm-6">
65+
<Chart ChartType="ChartType.Bar" OnInitAsync="() => OnInitStackedShowDataLabel(false)" Height="400px" Width="360px" />
66+
</div>
67+
<div class="col-12 col-sm-6">
68+
<Chart ChartType="ChartType.Bar" OnInitAsync="() => OnInitStackedShowDataLabel(true)" Height="400px" Width="360px" />
69+
</div>
70+
</div>
6471
</DemoBlock>
6572

6673
<DemoBlock Title="@Localizer["BarTotalDataLabelTitle"]"

src/BootstrapBlazor.Server/Components/Samples/Charts/Bar.razor.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,15 @@ private Task<ChartDataSource> OnInitShowDataLabel(bool showDataLabel)
223223
return Task.FromResult(ds);
224224
}
225225

226-
private Task<ChartDataSource> OnInitStackedShowDataLabel()
226+
private Task<ChartDataSource> OnInitStackedShowDataLabel(bool center)
227227
{
228228
var ds = new ChartDataSource();
229-
ds.Options.Title = "Stacked with zero value segment";
229+
ds.Options.Title = center ? "Anchor: Center" : "Anchor: End";
230230
ds.Options.ShowDataLabel = true;
231+
if (center)
232+
{
233+
ds.Options.Anchor = ChartDataLabelPosition.Center;
234+
}
231235
ds.Options.X.Title = "name";
232236
ds.Options.Y.Title = "Numerical value";
233237
ds.Options.X.Stacked = true;

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@
12621262
"BarShowDataLabelIntro": "By setting <code>ShowDataLabel</code> property,control whether to display chart data values",
12631263
"BarShowDataLabelTitle": "Display chart data values",
12641264
"BarStackedIntro": "By setting the X/Y axis <code>Stacked</code> property, control whether to stack the arrangement",
1265-
"BarStackedShowDataLabelIntro": "When <code>ShowDataLabel</code> is enabled in stacked mode, segments with a value of <code>0</code> do not draw data labels to avoid overlapping with adjacent segment labels. In this example, the top segment of <b>Bob</b> has a value of <code>0</code>, so only the lower segment's data label is displayed",
1265+
"BarStackedShowDataLabelIntro": "When <code>ShowDataLabel</code> is enabled in stacked mode, the position of the data label is controlled by the <code>Anchor</code> property. The default <code>End</code> displays it at the top of the segment, and <code>Center</code> displays it in the center of the segment. Segments with a value of <code>0</code> do not draw data labels to avoid overlapping with adjacent segment labels. In this example, the top segment of <b>Bob</b> has a value of <code>0</code>, so only the lower segment's data label is displayed",
12661266
"BarStackedShowDataLabelTitle": "Stacked Data Label",
12671267
"BarStackedTitle": "Stacked",
12681268
"BarTotalDataLabelIntro": "In stacked mode, set the <code>ShowTotalDataLabel</code> property to display the total data label above each bar. The total value is automatically recalculated when a dataset is hidden by clicking the legend. In this example, the <code>total</code> label is customized by the client script <code>setOptionsById</code>: the total text is formatted as <code>Total: {X}</code>, and the text color, background color, border radius, padding and font style are customized",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@
12621262
"BarShowDataLabelIntro": "通过设置<code>ShowDataLabel</code> 属性,控制是否显示数据值",
12631263
"BarShowDataLabelTitle": "显示图表数据值",
12641264
"BarStackedIntro": "通过设置 X/Y 轴 <code>Stacked</code> 属性,控制是否堆砌排列",
1265-
"BarStackedShowDataLabelIntro": "堆叠模式开启 <code>ShowDataLabel</code> 时,值为 <code>0</code> 的分段不绘制数据标签,避免与相邻分段标签重叠。本例中 <b>Bob</b> 顶部分段值为 <code>0</code>,仅显示下方分段的数据标签",
1265+
"BarStackedShowDataLabelIntro": "堆叠模式开启 <code>ShowDataLabel</code> 时,通过 <code>Anchor</code> 属性控制数据标签位置,默认 <code>End</code> 显示在分段顶部,设置为 <code>Center</code> 时显示在分段中间;值为 <code>0</code> 的分段不绘制数据标签,避免与相邻分段标签重叠。本例中 <b>Bob</b> 顶部分段值为 <code>0</code>,仅显示下方分段的数据标签",
12661266
"BarStackedShowDataLabelTitle": "堆叠图数据标签",
12671267
"BarStackedTitle": "堆砌排列",
12681268
"BarTotalDataLabelIntro": "堆叠模式通过设置 <code>ShowTotalDataLabel</code> 属性,在每个柱条顶部显示总计数据标签,点击图例隐藏数据集时总计值自动重新计算。本例中通过客户端脚本 <code>setOptionsById</code> 自定义 <code>total</code> 标签,将总计文本自定义为 <code>Total: {X}</code> 格式,并自定义了文字颜色、背景色、圆角、内边距与字体样式",

0 commit comments

Comments
 (0)