Skip to content

Commit 45f4149

Browse files
authored
Merge pull request #73 from apexcharts/fix-datapoints-selection
Fixed datapoint selection for mixed charts
2 parents acc92d1 + 864269d commit 45f4149

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

docs/BlazorApexCharts.Docs/Components/Events/DataPointSelection/Basic.razor

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,23 @@
77
OnDataPointSelection=DataPointsSelected
88
@ref=chart>
99

10-
<ApexPointSeries TItem="Order"
10+
<ApexPointSeries TItem="Order"
1111
Items="Orders"
12-
Name="Gross Value"
12+
Name="Net Value"
1313
SeriesType="SeriesType.Line"
1414
XValue="@(e => e.Country)"
15-
YAggregate="@(e => e.Sum(e => e.GrossValue))"
15+
YAggregate="@(e => e.Sum(e => e.NetValue))"
1616
OrderByDescending="e=>e.X" />
1717

1818
<ApexPointSeries TItem="Order"
1919
Items="Orders"
20-
Name="Net Value"
21-
SeriesType="SeriesType.Line"
20+
Name="Gross Value"
21+
SeriesType="SeriesType.Bar"
2222
XValue="@(e => e.Country)"
23-
YAggregate="@(e => e.Sum(e => e.NetValue))"
23+
YAggregate="@(e => e.Sum(e => e.GrossValue))"
2424
OrderByDescending="e=>e.X" />
25+
26+
2527
</ApexChart>
2628
</DemoContainer>
2729

src/Blazor-ApexCharts/ApexChart.razor.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ public partial class ApexChart<TItem> : IDisposable where TItem : class
3939
private string chartId;
4040
public string ChartId => ChartId;
4141

42-
43-
44-
4542
protected override async Task OnAfterRenderAsync(bool firstRender)
4643
{
4744
if (firstRender && isReady == false)
@@ -223,13 +220,28 @@ private void UpdateDataForNoAxisCharts()
223220
{
224221
Options.Colors = colors;
225222
}
226-
223+
}
224+
225+
226+
private bool ShouldFixDataSelection()
227+
{
228+
if (!OnDataPointSelection.HasDelegate || !Options.Series.Any()) { return false; }
229+
230+
if(Options.Chart?.Type != null && Options.Chart.Type == ChartType.Line || Options.Chart.Type == ChartType.Area || Options.Chart.Type == ChartType.Radar)
231+
{
232+
return true;
233+
}
234+
235+
if(Options.Series.Any(e=> e.Type == MixedType.Line || e.Type == MixedType.Area)) {
236+
return true;
237+
}
227238

239+
return false;
228240
}
229241

230242
private void FixLineDataSelection()
231243
{
232-
if ((Options.Chart.Type == ChartType.Line || Options.Chart.Type == ChartType.Area || Options.Chart.Type == ChartType.Radar) && OnDataPointSelection.HasDelegate)
244+
if (ShouldFixDataSelection())
233245
{
234246
if (Options.Tooltip == null) { Options.Tooltip = new Tooltip(); }
235247
if (Options.Markers == null) { Options.Markers = new Markers(); }

0 commit comments

Comments
 (0)