-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from apexcharts/add-xAxisLabelClick-event
Added XAxisLabelClick
- Loading branch information
Showing
9 changed files
with
243 additions
and
3 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
docs/BlazorApexCharts.Docs/Components/Events/XAxisLabelClick/Basic.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<DemoContainer> | ||
<ApexChart TItem="Order" | ||
Title="Order Net Value" | ||
OnXAxisLabelClick=XAxisLabelClick | ||
@ref=chart> | ||
|
||
<ApexPointSeries TItem="Order" | ||
Items="Orders" | ||
Name="Gross Value" | ||
SeriesType="SeriesType.Line" | ||
XValue="@(e => e.Country)" | ||
YAggregate="@(e => e.Sum(e => e.GrossValue))" | ||
OrderByDescending="e=>e.X" /> | ||
|
||
<ApexPointSeries TItem="Order" | ||
Items="Orders" | ||
Name="Net Value" | ||
SeriesType="SeriesType.Line" | ||
XValue="@(e => e.Country)" | ||
YAggregate="@(e => e.Sum(e => e.NetValue))" | ||
OrderByDescending="e=>e.X" /> | ||
</ApexChart> | ||
</DemoContainer> | ||
|
||
@if (selectedData != null) | ||
{ | ||
<Alert BackgroundColor="TablerColor.Primary"> | ||
<h3>You clicked: @selectedData.Caption [@selectedData.LabelIndex] </h3> | ||
|
||
@foreach (var seriesPoint in selectedData.SeriesPoints) | ||
{ | ||
var dataPoint = (DataPoint<Order>)seriesPoint.DataPoint; | ||
<div>@seriesPoint.Series.Name: @dataPoint.Y</div> | ||
} | ||
|
||
</Alert> | ||
} | ||
|
||
@code { | ||
private List<Order> Orders { get; set; } = SampleData.GetOrders(); | ||
private XAxisLabelClicked<Order> selectedData; | ||
private ApexChart<Order> chart; | ||
|
||
private void XAxisLabelClick(XAxisLabelClicked<Order> data) | ||
{ | ||
selectedData = data; | ||
|
||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
docs/BlazorApexCharts.Docs/Components/Events/XAxisLabelClick/DateTime.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<DemoContainer> | ||
<ApexChart TItem="Order" Title="Orders Value" | ||
XAxisType="XAxisType.Datetime" | ||
Options="options" | ||
OnXAxisLabelClick=XAxisLabelClick | ||
Debug> | ||
|
||
<ApexPointSeries TItem="Order" | ||
Items="SampleData.GetOrders()" | ||
Name="Net Value" | ||
SeriesType="SeriesType.Line" | ||
XValue="@(e => e.OrderDate.FirstDayOfMonth())" | ||
YAggregate="@(e => e.Sum(e => e.NetValue))" | ||
OrderBy="e=>e.X" /> | ||
|
||
<ApexPointSeries TItem="Order" | ||
Items="SampleData.GetOrders()" | ||
Name="Gross Value" | ||
SeriesType="SeriesType.Line" | ||
XValue="@(e => e.OrderDate.FirstDayOfMonth())" | ||
YAggregate="@(e => e.Sum(e => e.GrossValue))" | ||
OrderBy="e=>e.X" /> | ||
</ApexChart> | ||
|
||
@if (selectedData != null) | ||
{ | ||
<Alert BackgroundColor="TablerColor.Primary"> | ||
<h3>You clicked: @selectedData.Caption [@selectedData.LabelIndex] </h3> | ||
|
||
@foreach (var seriesPoint in selectedData.SeriesPoints) | ||
{ | ||
var dataPoint = (DataPoint<Order>)seriesPoint.DataPoint; | ||
<div>@seriesPoint.Series.Name - @dataPoint.Y</div> | ||
} | ||
|
||
</Alert> | ||
} | ||
|
||
</DemoContainer> | ||
|
||
@code { | ||
private ApexChartOptions<Order> options = new ApexCharts.ApexChartOptions<Order>(); | ||
private XAxisLabelClicked<Order> selectedData; | ||
private void XAxisLabelClick(XAxisLabelClicked<Order> data) | ||
{ | ||
|
||
selectedData = data; | ||
|
||
} | ||
|
||
protected override void OnInitialized() | ||
{ | ||
|
||
options.Debug = true; | ||
options.ForecastDataPoints = new ForecastDataPoints | ||
{ | ||
Count = 3, | ||
DashArray = 4, | ||
FillOpacity = 0.5, | ||
}; | ||
options.Tooltip = new ApexCharts.Tooltip { X = new TooltipX { Format = @"MMMM \ yyyy" } }; | ||
options.Subtitle = new Subtitle { OffsetY = 15, Text = "DateTime sample with options" }; | ||
options.Tooltip = new ApexCharts.Tooltip | ||
{ | ||
Y = new TooltipY | ||
{ | ||
Title = new TooltipYTitle { Formatter = @"function(name) { return name + ':' }" }, | ||
Formatter = @"function(value, { series, seriesIndex, dataPointIndex, w }) { return '$' + value }" | ||
}, | ||
}; | ||
options.Xaxis = new XAxis | ||
{ | ||
Title = new AxisTitle | ||
{ | ||
OffsetY = 5, | ||
Text = "Month", | ||
Style = new AxisTitleStyle { FontSize = "14px", Color = "lightgrey" } | ||
}, | ||
AxisBorder = new AxisBorder | ||
{ | ||
Height = 2 | ||
} | ||
}; | ||
options.Yaxis = new List<YAxis>(); | ||
options.Yaxis.Add(new YAxis | ||
{ | ||
DecimalsInFloat = 0, | ||
Labels = new YAxisLabels { Rotate = -45, Style = new AxisLabelStyle { FontSize = "10px" } }, | ||
Title = new AxisTitle { Text = "Value", Style = new AxisTitleStyle { FontSize = "14px", Color = "lightgrey" } } | ||
}); | ||
|
||
options.Annotations = new Annotations { Yaxis = new List<AnnotationsYAxis>() }; | ||
options.Annotations.Yaxis.Add(new AnnotationsYAxis | ||
{ | ||
Y = 50000, | ||
BorderWidth = 2, | ||
StrokeDashArray = 5, | ||
BorderColor = "red", | ||
Label = new Label { Text = "Monthly Target" } | ||
}); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
docs/BlazorApexCharts.Docs/Components/Events/XAxisLabelClick/XAxisLabelClickDocs.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@page "/events/xaxis-label-click" | ||
|
||
<DocExamples Title="X Axis Label Click"> | ||
|
||
<Description> | ||
Click on a XAxis label to trigger an event | ||
</Description> | ||
|
||
<ChildContent> | ||
|
||
<CodeSnippet Title="Basic" ClassName=@typeof(Basic).ToString()> | ||
<Snippet> | ||
<Basic /> | ||
</Snippet> | ||
</CodeSnippet> | ||
|
||
<CodeSnippet Title="DateTime" ClassName=@typeof(DateTime).ToString()> | ||
<Snippet> | ||
<DateTime /> | ||
</Snippet> | ||
</CodeSnippet> | ||
|
||
</ChildContent> | ||
|
||
|
||
</DocExamples> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace ApexCharts | ||
{ | ||
public class XAxisLabelClicked<TItem> where TItem : class | ||
{ | ||
public int LabelIndex { get; set; } | ||
public string Caption { get; set; } | ||
public List<SeriesDataPoint<TItem>> SeriesPoints { get; set; } | ||
|
||
} | ||
|
||
public class SeriesDataPoint<TItem> where TItem : class | ||
{ | ||
public Series<TItem> Series { get; set; } | ||
public IDataPoint<TItem> DataPoint { get; set; } | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters