Skip to content

Commit 2e61399

Browse files
authored
Merge pull request #273 from apexcharts/improve-methods
Improved methods
2 parents 987db09 + 04d85f7 commit 2e61399

File tree

8 files changed

+109
-51
lines changed

8 files changed

+109
-51
lines changed

docs/BlazorApexCharts.Docs/Components/Features/ChartSize/Basic.razor

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11

2-
<Row>
3-
<RowCol Auto>
4-
<label class="form-label">Width</label>
5-
<input type="number" @bind=@width class="form-control" />
6-
</RowCol>
7-
<RowCol Auto>
8-
<label class="form-label">Height</label>
9-
<input type="number" @bind=@height class="form-control" />
10-
</RowCol>
11-
</Row>
12-
13-
<Row class="mt-2 mb-2">
14-
<RowCol Auto>
15-
<Button BackgroundColor="TablerColor.Primary" OnClick="UpdateSize">Update Size</Button>
16-
</RowCol>
17-
</Row>
18-
19-
<div style="overflow-x:scroll;overflow-y:hidden">
2+
<Row>
3+
<RowCol Auto>
4+
<label class="form-label">Width</label>
5+
<input type="number" @bind=@width class="form-control" />
6+
</RowCol>
7+
<RowCol Auto>
8+
<label class="form-label">Height</label>
9+
<input type="number" @bind=@height class="form-control" />
10+
</RowCol>
11+
</Row>
12+
13+
<Row class="mt-2 mb-2">
14+
<RowCol Auto>
15+
<Button BackgroundColor="TablerColor.Primary" OnClick="UpdateSize">Update Size</Button>
16+
</RowCol>
17+
</Row>
18+
19+
<div style="overflow-x:scroll;overflow-y:hidden">
2020
<ApexChart TItem="Order"
2121
Title="Scatter Sample"
2222
Width="@width"
@@ -39,7 +39,7 @@
3939
YAggregate="@(e => e.Sum(e => e.NetValue))"
4040
OrderByDescending="e=>e.Y" />
4141
</ApexChart>
42-
</div>
42+
</div>
4343

4444

4545
@code {
@@ -50,7 +50,6 @@
5050

5151
private async Task UpdateSize()
5252
{
53-
await Task.Yield();
5453
await chart.UpdateOptionsAsync(false, false, false);
5554
}
5655

docs/BlazorApexCharts.Docs/Components/Methods/UpdateOptions/Basic.razor

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,12 @@
5858
private async Task RenderChart()
5959
{
6060
ToogleColor();
61-
await Task.Delay(10);
6261
await chart.RenderAsync();
6362
}
6463

6564
private async Task UpdateOptions()
6665
{
6766
ToogleColor();
68-
await Task.Delay(10);
6967
await chart.UpdateOptionsAsync(redrawPaths, animate, false);
7068
}
7169
}

docs/BlazorApexCharts.Docs/Components/Methods/UpdateOptions/MaintainZoom.razor

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@
6363

6464
title = "Order Net Value " + dateString;
6565
seriesName = "Gross Value " + dateString;
66-
67-
await Task.Yield(); // We need this in order to update the title and series name
68-
66+
6967
await chart.UpdateOptionsAsync(false, false, false, zoomOptions);
7068
}
7169
}
Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,59 @@
1-
<DemoContainer>
1+
2+
<DemoContainer>
23

3-
<Button class="mb-2" OnClick=UpdateChartSeries BackgroundColor="TablerColor.Primary">Update Series</Button>
4+
<Button class="mb-2" OnClick=UpdateChartSeries BackgroundColor="TablerColor.Primary">Update Series</Button>
45

6+
@if (forecasts != null)
7+
{
8+
<ApexChart TItem="WeatherForecast"
9+
Title="Temp C"
10+
XAxisType="XAxisType.Datetime"
11+
@ref="chart">
12+
13+
<ApexPointSeries TItem="WeatherForecast"
14+
Items="forecasts"
15+
Name="Temp C"
16+
XValue="@(e => e.Date.ToUnixTimeMilliseconds())"
17+
YAggregate="@(e => e.Sum(f => f.TemperatureC))"
18+
SeriesType="SeriesType.Bar"
19+
Color="#005ba3" />
20+
</ApexChart>
21+
}
522

6-
<ApexChart TItem="Order"
7-
Title="Order Gross Value"
8-
@ref=chart>
923

10-
<ApexPointSeries TItem="Order"
11-
Items="orders"
12-
Name="Gross Value"
13-
SeriesType="SeriesType.Pie"
14-
XValue="@(e => e.Country)"
15-
YAggregate="@(e => e.Sum(e => e.GrossValue))"
16-
OrderByDescending="e=>e.X" />
17-
</ApexChart>
1824
</DemoContainer>
1925

2026
<div>
21-
@message
27+
<Table Items="forecasts">
28+
<Column Item="WeatherForecast" Property="e=> e.Date">
29+
<Template>
30+
@context.Date.ToString("D")
31+
</Template>
32+
</Column>
33+
<Column Item="WeatherForecast" Property="e=> e.TemperatureC" />
34+
<Column Item="WeatherForecast" Property="e=> e.Summary" />
35+
</Table>
2236
</div>
2337
@code {
24-
private List<Order> orders { get; set; } = SampleData.GetOrders();
25-
private ApexChart<Order> chart;
38+
private List<WeatherForecast> forecasts { get; set; }
39+
private ApexChart<WeatherForecast> chart;
2640
private string message;
41+
42+
protected override async Task OnInitializedAsync()
43+
{
44+
await LoadDataAsync();
45+
46+
await base.OnInitializedAsync();
47+
}
48+
49+
private async Task LoadDataAsync()
50+
{
51+
forecasts = (await SampleData.GetForecastAsync(DateTime.Today)).ToList();
52+
}
53+
2754
private async Task UpdateChartSeries()
2855
{
29-
var order = orders.First();
30-
message = order.Country;
31-
order.GrossValue = order.GrossValue * (decimal)1.6;
56+
await LoadDataAsync();
3257
await chart.UpdateSeriesAsync(true);
3358
}
34-
}
59+
}

docs/BlazorApexCharts.Docs/Components/Methods/UpdateSeries/FillColor.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
var order = orders.First();
3333
message = order.Country;
3434
order.GrossValue = order.GrossValue * (decimal)1.6;
35-
// await chart.UpdateSeriesAsync(true);
3635
await chart.UpdateOptionsAsync(false, false, false);
3736
}
3837

docs/BlazorApexCharts.Docs/Data/SampleData.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,38 @@
22
using Bogus;
33
using System;
44
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Threading.Tasks;
57

68
namespace BlazorApexCharts.Docs
79
{
810
public static class SampleData
911
{
12+
private static readonly string[] Summaries = new[]
13+
{
14+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
15+
};
16+
17+
public static Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
18+
{
19+
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
20+
{
21+
Date = startDate.AddDays(index),
22+
TemperatureC = Random.Shared.Next(-20, 55),
23+
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
24+
}).ToArray());
25+
}
26+
1027
public static List<BoxPlotSample> GetBoxPlotData()
1128
{
1229

1330
var now = DateTimeOffset.Now;
1431
var result = new List<BoxPlotSample>();
1532

16-
result.Add(new BoxPlotSample { Name = "Eva", EventDate=now.AddDays(-10), Min = 40, Q1 = 52, Median = 56.59m, Q3 = 60, Max = 63.85m } );
33+
result.Add(new BoxPlotSample { Name = "Eva", EventDate = now.AddDays(-10), Min = 40, Q1 = 52, Median = 56.59m, Q3 = 60, Max = 63.85m });
1734
result.Add(new BoxPlotSample { Name = "Jonas", EventDate = now.AddDays(-9), Min = 43.66m, Q1 = 44.99m, Median = 51.35m, Q3 = 52.95m, Max = 59.42m });
1835
result.Add(new BoxPlotSample { Name = "Bart", EventDate = now.AddDays(-8), Min = 52.76m, Q1 = 57.35m, Median = 59.15m, Q3 = 63.03m, Max = 67.98m });
19-
result.Add(new BoxPlotSample { Name = "Cecilia", EventDate = now.AddDays(-7), Min = 48m, Q1 = 49m, Median = 52m, Q3 = 62m, Max =68m });
36+
result.Add(new BoxPlotSample { Name = "Cecilia", EventDate = now.AddDays(-7), Min = 48m, Q1 = 49m, Median = 52m, Q3 = 62m, Max = 68m });
2037
result.Add(new BoxPlotSample { Name = "Ann", EventDate = now.AddDays(-6), Min = 38m, Q1 = 41m, Median = 45m, Q3 = 52m, Max = 55m });
2138
return result;
2239
}
@@ -65,7 +82,7 @@ public static List<Order> GetOrdersForGroup()
6582

6683
}
6784

68-
public static List<Order> GetOrders()
85+
public static List<Order> GetOrders()
6986
{
7087
var orders = new List<Order>();
7188
orders.Add(new Order { CustomerName = "Odio Corporation", Country = "Sweden", OrderDate = DateTimeOffset.Now.AddDays(-12), GrossValue = 34531, DiscountPercentage = 21, OrderType = OrderType.Contract });
@@ -115,7 +132,7 @@ public static List<Project> GetProjects()
115132
result.Add(new Project { Name = "Design", StartDate = DateTime.Now.AddDays(-30), EndDate = DateTime.Now.AddDays(-10), Score = 20 });
116133
result.Add(new Project { Name = "Construct", StartDate = DateTime.Now.AddDays(-20), EndDate = DateTime.Now.AddDays(-5), Score = -12 });
117134
result.Add(new Project { Name = "Install", StartDate = DateTime.Now.AddDays(-14), EndDate = DateTime.Now.AddDays(0), Score = -4 });
118-
result.Add(new Project { Name = "Train", StartDate = DateTime.Now.AddDays(-18), EndDate = DateTime.Now.AddDays(5), Score = 26 });
135+
result.Add(new Project { Name = "Train", StartDate = DateTime.Now.AddDays(-18), EndDate = DateTime.Now.AddDays(5), Score = 26 });
119136
return result;
120137

121138
}
@@ -145,7 +162,7 @@ public static List<SupportIncident> GetSupportIncidents(int severityMin = 0, int
145162
.RuleFor(o => o.Source, f => f.PickRandom<IncidentSource>())
146163
.RuleFor(o => o.LeadTime, f => f.Random.Number(1, 10))
147164
.RuleFor(o => o.WeekNumber, f => f.Random.Number(1, 20))
148-
.RuleFor(o => o.PointColor, f=> f.Internet.Color());
165+
.RuleFor(o => o.PointColor, f => f.Internet.Color());
149166

150167
var test = fakeIncidents.Generate(300);
151168
return test;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace BlazorApexCharts.Docs
8+
{
9+
public class WeatherForecast
10+
{
11+
public DateTime Date { get; set; }
12+
13+
public int TemperatureC { get; set; }
14+
15+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
16+
17+
public string Summary { get; set; }
18+
}
19+
}

src/Blazor-ApexCharts/ApexChart.razor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ public virtual async Task RemoveAnnotationAsync(string id)
663663
/// </remarks>
664664
public virtual async Task UpdateOptionsAsync(bool redrawPaths, bool animate, bool updateSyncedCharts, ZoomOptions zoom = null)
665665
{
666+
await Task.Yield();
666667
PrepareChart();
667668
var json = Serialize(Options);
668669
await JSRuntime.InvokeVoidAsync("blazor_apexchart.updateOptions", Options.Chart.Id, json, redrawPaths, animate, updateSyncedCharts, zoom);
@@ -680,6 +681,7 @@ public virtual async Task UpdateOptionsAsync(bool redrawPaths, bool animate, boo
680681
/// </remarks>
681682
public virtual async Task UpdateSeriesAsync(bool animate = true)
682683
{
684+
await Task.Yield();
683685
SetSeries();
684686
UpdateDataForNoAxisCharts();
685687
var jsonSeries = Serialize(Options.Series);
@@ -768,6 +770,7 @@ private void SetEvents()
768770

769771
private async Task RenderChartAsync()
770772
{
773+
await Task.Yield();
771774
forceRender = false;
772775
PrepareChart();
773776
var jsonOptions = Serialize(Options);

0 commit comments

Comments
 (0)