Skip to content

Commit 39b1174

Browse files
committed
Added Stroke settings on series
1 parent c2695bd commit 39b1174

File tree

10 files changed

+108
-9
lines changed

10 files changed

+108
-9
lines changed

samples/ChartSamples/Pages/BasicCharts.razor

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
<ApexChart TItem="Order" Title="Orders Net Value By Type"
1616
OnDataPointSelection="DataPointSelected"
1717
ChartType="@pieChartType">
18-
18+
1919
<ApexSeries TItem="Order"
2020
Items="Orders"
2121
Name="Order Value"
2222
XValue="@(e => e.OrderType)"
2323
YAggregate="@(e => e.Sum(e => e.NetValue))"
24-
ShowDataLabels="true" />
24+
ShowDataLabels="true"
25+
/>
2526
</ApexChart>
2627
</div>
2728

@@ -48,14 +49,16 @@
4849
Name="Gross Value"
4950
XValue="@(e => e.Country)"
5051
YAggregate="@(e => e.Sum(e => e.GrossValue))"
51-
OrderByDescending="e=>e.Y" />
52+
OrderByDescending="e=>e.Y"
53+
/>
5254

5355
<ApexSeries TItem="Order"
5456
Items="Orders"
5557
Name="Net Value"
5658
XValue="@(e => e.Country)"
5759
YAggregate="@(e => e.Sum(e => e.NetValue))"
58-
OrderByDescending="e=>e.Y" />
60+
OrderByDescending="e=>e.Y"
61+
/>
5962

6063
</ApexChart>
6164
</div>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
@page "/series-options"
2+
3+
<h3>Series Options</h3>
4+
5+
<p class="mb-3">
6+
7+
<ul>
8+
<li>Use the Stroke setting on the series to control color, width and dash settings</li>
9+
<li>Use ShowDataLabels to show the datalabels on each value</li>
10+
</ul>
11+
12+
13+
Please note that the color must be either hex or rgb/rgba format. Color names are not accepted at the moment in apexchart.js.
14+
</p>
15+
16+
<ApexChart TItem="Order"
17+
Title="Order Net Value"
18+
ChartType="@ChartType.Line">
19+
20+
<ApexSeries TItem="Order"
21+
Items="Orders"
22+
Name="Gross Value"
23+
XValue="@(e => e.Country)"
24+
YAggregate="@(e => e.Sum(e => e.GrossValue))"
25+
OrderByDescending="e=>e.Y"
26+
Stroke="@(new ApexCharts.SeriesStroke { Color = "#FF0000", DashSpace = 0, Width = 5 })"
27+
ShowDataLabels
28+
/>
29+
30+
31+
<ApexSeries TItem="Order"
32+
Items="Orders"
33+
Name="Net Value"
34+
XValue="@(e => e.Country)"
35+
YAggregate="@(e => e.Sum(e => e.NetValue))"
36+
OrderByDescending="e=>e.Y"
37+
Stroke="@(new ApexCharts.SeriesStroke { Color = "#000080", DashSpace = 3, Width = 3 })" />
38+
39+
</ApexChart>
40+
41+
@code {
42+
private List<Order> Orders { get; set; } = SampleData.GetOrders();
43+
44+
45+
}

samples/ChartSamples/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"IIS Express": {
1212
"commandName": "IISExpress",
1313
"launchBrowser": true,
14-
"launchUrl": "Blazor-ApexCharts/sparklines",
14+
"launchUrl": "Blazor-ApexCharts/series-options",
1515
"environmentVariables": {
1616
"ASPNETCORE_ENVIRONMENT": "Development"
1717
},

samples/ChartSamples/Shared/NavMenu.razor

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,21 @@
3333
</NavLink>
3434
</li>
3535

36+
37+
<li class="nav-item px-3">
38+
<NavLink class="nav-link" href="series-options">
39+
<span class="oi oi-resize-width" aria-hidden="true"></span>Series options
40+
</NavLink>
41+
</li>
42+
3643
<li class="nav-item px-3">
3744
<NavLink class="nav-link" href="render-chart">
3845
<span class="oi oi-reload" aria-hidden="true"></span>Render Chart
3946
</NavLink>
4047
</li>
4148

42-
49+
50+
4351

4452
</ul>
4553
</div>

src/Blazor-ApexCharts/ApexBubbleSeries.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class ApexBubbleSeries<TItem> : ComponentBase, IDisposable where TItem :
2020
[Parameter] public Expression<Func<BubblePoint<TItem>, object>> OrderBy { get; set; }
2121
[Parameter] public Expression<Func<BubblePoint<TItem>, object>> OrderByDescending { get; set; }
2222
[Parameter] public bool ShowDataLabels { get; set; }
23+
[Parameter] public string Color { get; set; }
2324
[Parameter] public IEnumerable<TItem> Items { get; set; }
2425
private readonly Series<TItem> series = new Series<TItem>();
2526
protected override void OnParametersSet()
@@ -28,7 +29,7 @@ protected override void OnParametersSet()
2829

2930
series.Name = Name;
3031
series.ShowDataLabels = ShowDataLabels;
31-
32+
3233
//var xCompiled = XValue.Compile();
3334
//IEnumerable<BubblePoint<TItem>> datalist;
3435
//if (YAggregate == null)

src/Blazor-ApexCharts/ApexChart.razor.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public partial class ApexChart<TItem> : IDisposable where TItem : class
1616
[Parameter] public RenderFragment ChildContent { get; set; }
1717
[Parameter] public ApexChartOptions<TItem> Options { get; set; } = new ApexChartOptions<TItem>();
1818
[Parameter] public string Title { get; set; }
19-
19+
2020
[Parameter]
2121
public ChartType ChartType
2222
{
@@ -84,6 +84,29 @@ protected override void OnParametersSet()
8484
}
8585
}
8686

87+
private void SetStroke()
88+
{
89+
if (Options?.Series == null) { return; }
90+
if (Options.Series.All(e => (e.Stroke == null))) { return; }
91+
92+
if (Options.Stroke == null) { Options.Stroke = new Stroke(); }
93+
94+
var strokeWidths = new List<int>();
95+
var strokeColors = new List<string>();
96+
var strokeDash = new List<int>();
97+
foreach (var series in Options.Series)
98+
{
99+
strokeWidths.Add(series.Stroke?.Width ?? 4); //
100+
strokeColors.Add(series.Stroke?.Color ?? "#d3d3d3"); //Default is light gray
101+
strokeDash.Add(series.Stroke?.DashSpace ?? 0);
102+
}
103+
104+
Options.Colors = strokeColors;
105+
Options.Stroke.Width = strokeWidths;
106+
Options.Stroke.Colors = strokeColors;
107+
Options.Stroke.DashArray = strokeDash;
108+
}
109+
87110
private void SetDatalabels()
88111
{
89112
if (Options?.Series == null) { return; }
@@ -160,6 +183,7 @@ public void FixLineDataSelection()
160183
public async Task Render()
161184
{
162185
ForceRender = false;
186+
SetStroke();
163187
SetDatalabels();
164188
FixLineDataSelection();
165189
UpdateDataForNoAxisCharts();

src/Blazor-ApexCharts/ApexSeries.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ public class ApexSeries<TItem> : ComponentBase, IDisposable where TItem : class
2121
[Parameter] public Expression<Func<DataPoint<TItem>, object>> OrderByDescending { get; set; }
2222
[Parameter] public bool ShowDataLabels { get; set; }
2323
[Parameter] public IEnumerable<TItem> Items { get; set; }
24+
[Parameter] public SeriesStroke Stroke { get; set; }
25+
2426
private readonly Series<TItem> series = new Series<TItem>();
2527
private IEnumerable<DataPoint<TItem>> currentDatalist;
2628

2729
protected override async Task OnParametersSetAsync()
2830
{
2931
series.Name = Name;
3032
series.ShowDataLabels = ShowDataLabels;
31-
33+
series.Stroke = Stroke;
3234
var xCompiled = XValue.Compile();
3335
IEnumerable<DataPoint<TItem>> datalist;
3436
if (YAggregate == null)

src/Blazor-ApexCharts/Models/Series.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@ public class Series<TItem>
2929

3030
[JsonIgnore]
3131
public bool ShowDataLabels { get; set; }
32+
[JsonIgnore]
33+
public SeriesStroke Stroke { get; set; }
3234
}
3335
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace ApexCharts
6+
{
7+
public class SeriesStroke
8+
{
9+
public string Color { get; set; }
10+
public int DashSpace { get; set; }
11+
public int Width { get; set; }
12+
}
13+
}

src/Blazor-ApexCharts/wwwroot/js/blazor-apex-charts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
renderChart(dotNetObject, container, options) {
1414
var options = JSON.parse(options);
1515

16+
console.log(options);
1617
if (options.debug == true) {
1718
console.log(options);
1819
}

0 commit comments

Comments
 (0)