Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,4 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml
/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@namespace BlazorExpress.ChartJS.Demo.RCL

<Section Class="p-0" Size="HeadingSize.H4" Name="Prerequisites" PageUrl="@PageUrl" Link="prerequisites">
<Block>
Refer to the <a href="@DemoRouteConstants.Docs_Getting_Started_Introduction">Getting Started guide</a> for setting up charts.
</Block>
</Section>

@code {
[Parameter]
public string? PageUrl { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
<Demo Type="typeof(BarChart_Demo_01_Examples)" Tabs="true" />
</Section>

<Section Class="p-0" Size="HeadingSize.H4" Name="Click event" PageUrl="@pageUrl" Link="click-event">
<Block>
Set the <code>OnClick</code> callback to react when a chart data item is selected. The callback receives <code>ChartClickEventArgs</code> with the dataset index and label, data-item index and label, and raw value.
The dedicated demo displays the selected item below the chart.
</Block>
<Demo Type="typeof(BarChart_Demo_11_Click_Event)" Tabs="true" />
</Section>

<Section Class="p-0" Size="HeadingSize.H4" Name="Combo bar/line" PageUrl="@pageUrl" Link="combo-bar-line">
<Block>
The <strong>Combo bar/line</strong> demo mixes <code>BarChartDataset</code> and <code>LineChartDataset</code> in the same <code>BarChart</code>.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<BarChart @ref="barChart" Width="600" />
<BarChart @ref="barChart" Width="600" OnClick="HandleClickAsync" />

@if (selectedChartItem is not null)
{
<p class="mt-3 mb-0">
Selected: @selectedChartItem.DatasetLabel (dataset @selectedChartItem.DatasetIndex), @selectedChartItem.Label (index @selectedChartItem.Index), value @selectedChartItem.Value
</p>
}

<div class="mt-5">
<Button Color="ButtonColor.Primary" Size="ButtonSize.Small" @onclick="RandomizeAsync"> Randomize </Button>
Expand All @@ -12,6 +19,7 @@
private BarChart barChart = default!;
private BarChartOptions barChartOptions = default!;
private ChartData chartData = default!;
private ChartClickEventArgs? selectedChartItem;

private int datasetsCount = 0;
private int labelsCount = 0;
Expand All @@ -33,6 +41,12 @@
await base.OnAfterRenderAsync(firstRender);
}

private Task HandleClickAsync(ChartClickEventArgs eventArgs)
{
selectedChartItem = eventArgs;
return Task.CompletedTask;
}

private async Task RandomizeAsync()
{
if (chartData is null || chartData.Datasets is null || !chartData.Datasets.Any()) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<BarChart @ref="barChart" Width="600" OnClick="HandleClickAsync" />

@if (selectedChartItem is not null)
{
<p class="mt-3 mb-0">
Selected: @selectedChartItem.DatasetLabel (dataset @selectedChartItem.DatasetIndex), @selectedChartItem.Label (index @selectedChartItem.Index), value @selectedChartItem.Value
</p>
}

@code {
private BarChart barChart = default!;
private BarChartOptions barChartOptions = default!;
private ChartData chartData = default!;
private ChartClickEventArgs? selectedChartItem;

protected override void OnInitialized()
{
chartData = new ChartData
{
Labels = new List<string> { "January", "February", "March" },
Datasets = new List<IChartDataset>
{
new BarChartDataset
{
Label = "Orders",
Data = new List<double?> { 45, 68, 54 },
BackgroundColor = new List<string> { "#36A2EB" },
},
},
};
barChartOptions = new BarChartOptions { Responsive = true };
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
await barChart.InitializeAsync(chartData, barChartOptions);

await base.OnAfterRenderAsync(firstRender);
}

private Task HandleClickAsync(ChartClickEventArgs eventArgs)
{
selectedChartItem = eventArgs;
return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
<Demo Type="typeof(BubbleChart_Demo_01_Examples)" Tabs="true" />
</Section>

<Section Class="p-0" Size="HeadingSize.H4" Name="Click event" PageUrl="@pageUrl" Link="click-event">
<Block>
Set the <code>OnClick</code> callback to react when a bubble is selected. The callback receives <code>ChartClickEventArgs</code> with the dataset, point index, and raw value; the demo displays the selected item below the chart.
</Block>
<Demo Type="typeof(BubbleChart_Demo_02_Click_Event)" Tabs="true" />
</Section>

@code {
private const string pageUrl = DemoRouteConstants.Demos_BubbleChart;
private const string pageTitle = "Bubble Chart";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<BubbleChart @ref="bubbleChart" Width="600" OnClick="HandleClickAsync" />

@if (selectedChartItem is not null)
{
<p class="mt-3 mb-0">
Selected: @selectedChartItem.DatasetLabel (dataset @selectedChartItem.DatasetIndex), @selectedChartItem.Label (index @selectedChartItem.Index), value @selectedChartItem.Value
</p>
}

@code {
private BubbleChart bubbleChart = default!;
private BubbleChartOptions bubbleChartOptions = default!;
private ChartData chartData = default!;
private ChartClickEventArgs? selectedChartItem;

protected override void OnInitialized()
{
chartData = new ChartData
{
Labels = new List<string> { "January", "February", "March" },
Datasets = new List<IChartDataset>
{
new BubbleChartDataset
{
Label = "Projects",
Data = new List<BubbleChartDataPoint>
{
new(10, 20, 8),
new(15, 12, 12),
new(8, 25, 6),
},
BackgroundColor = new List<string> { "rgba(255, 99, 132, 0.5)" },
BorderColor = new List<string> { "rgb(255, 99, 132)" },
BorderWidth = 1,
},
},
};
bubbleChartOptions = new BubbleChartOptions { Responsive = true };
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
await bubbleChart.InitializeAsync(chartData, bubbleChartOptions);

await base.OnAfterRenderAsync(firstRender);
}

private Task HandleClickAsync(ChartClickEventArgs eventArgs)
{
selectedChartItem = eventArgs;
return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,18 @@
<Demo Type="typeof(DoughnutChart_Demo_02_Datalabels)" Tabs="true" />
</Section>

<Section Class="p-0" Size="HeadingSize.H4" Name="Click event" PageUrl="@pageUrl" Link="click-event">
<Block>
Set the <code>OnClick</code> callback to react when a doughnut segment is selected. The callback receives <code>ChartClickEventArgs</code> with the dataset, item index, label, and raw value; the demo displays the selected item below the chart.
</Block>
<Demo Type="typeof(DoughnutChart_Demo_03_Click_Event)" Tabs="true" />
</Section>

@code {
private const string pageUrl = DemoRouteConstants.Demos_DoughnutChart;
private const string pageTitle = "Doughnut Chart";
private const string pageDescription = "Explore interactive <code>Blazor Doughnut Chart</code> demos with real-world examples. Learn how to visualize data, customize chart options, and implement data labels using the Blazor Doughnut Chart component.";
private const string metaTitle = "Blazor Doughnut Chart Demo & Examples";
private const string metaDescription = "Explore interactive Blazor Doughnut Chart demos with real-world examples. Learn how to visualize data, customize chart options, and implement data labels using the Blazor Doughnut Chart component.";
private const string imageUrl = DemoImageSrcConstants.DoughnutChart;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<DoughnutChart @ref="doughnutChart" Width="600" OnClick="HandleClickAsync" />

@if (selectedChartItem is not null)
{
<p class="mt-3 mb-0">
Selected: @selectedChartItem.DatasetLabel (dataset @selectedChartItem.DatasetIndex), @selectedChartItem.Label (index @selectedChartItem.Index), value @selectedChartItem.Value
</p>
}

@code {
private DoughnutChart doughnutChart = default!;
private DoughnutChartOptions doughnutChartOptions = default!;
private ChartData chartData = default!;
private ChartClickEventArgs? selectedChartItem;

protected override void OnInitialized()
{
chartData = new ChartData
{
Labels = new List<string> { "Direct", "Referral", "Social" },
Datasets = new List<IChartDataset>
{
new DoughnutChartDataset
{
Label = "Visitors",
Data = new List<double?> { 55, 30, 15 },
BackgroundColor = new List<string> { "#36A2EB", "#FF6384", "#FFCE56" },
},
},
};
doughnutChartOptions = new DoughnutChartOptions { Responsive = true };
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
await doughnutChart.InitializeAsync(chartData, doughnutChartOptions);

await base.OnAfterRenderAsync(firstRender);
}

private Task HandleClickAsync(ChartClickEventArgs eventArgs)
{
selectedChartItem = eventArgs;
return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@
<Demo Type="typeof(LineChart_Demo_05_Interpolation_Modes)" Tabs="true" />
</Section>

<Section Class="p-0" Size="HeadingSize.H4" Name="Click event" PageUrl="@pageUrl" Link="click-event">
<Block>
Set the <code>OnClick</code> callback to react when a line data point is selected. The callback receives <code>ChartClickEventArgs</code> with the dataset, point index, label, and raw value; the demo displays the selected item below the chart.
</Block>
<Demo Type="typeof(LineChart_Demo_08_Click_Event)" Tabs="true" />
</Section>

@code {
private const string pageUrl = DemoRouteConstants.Demos_LineChart;
private const string pageTitle = "Line Chart";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<LineChart @ref="lineChart" Width="600" OnClick="HandleClickAsync" />

@if (selectedChartItem is not null)
{
<p class="mt-3 mb-0">
Selected: @selectedChartItem.DatasetLabel (dataset @selectedChartItem.DatasetIndex), @selectedChartItem.Label (index @selectedChartItem.Index), value @selectedChartItem.Value
</p>
}

@code {
private LineChart lineChart = default!;
private LineChartOptions lineChartOptions = default!;
private ChartData chartData = default!;
private ChartClickEventArgs? selectedChartItem;

protected override void OnInitialized()
{
chartData = new ChartData
{
Labels = new List<string> { "Monday", "Tuesday", "Wednesday", "Thursday" },
Datasets = new List<IChartDataset>
{
new LineChartDataset
{
Label = "Visitors",
Data = new List<double?> { 120, 190, 150, 230 },
BackgroundColor = "rgba(54, 162, 235, 0.2)",
BorderColor = "rgb(54, 162, 235)",
PointRadius = new List<double> { 5 },
PointHoverRadius = new List<double> { 8 },
},
},
};
lineChartOptions = new LineChartOptions { Responsive = true };
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
await lineChart.InitializeAsync(chartData, lineChartOptions);

await base.OnAfterRenderAsync(firstRender);
}

private Task HandleClickAsync(ChartClickEventArgs eventArgs)
{
selectedChartItem = eventArgs;
return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@
<Demo Type="typeof(PieChart_Demo_03_Change_Legend_Position)" Tabs="true" />
</Section>

<Section Class="p-0" Size="HeadingSize.H4" Name="Click event" PageUrl="@pageUrl" Link="click-event">
<Block>
Set the <code>OnClick</code> callback to react when a pie slice is selected. The callback receives <code>ChartClickEventArgs</code> with the dataset, item index, label, and raw value; the demo displays the selected item below the chart.
</Block>
<Demo Type="typeof(PieChart_Demo_04_Click_Event)" Tabs="true" />
</Section>

@code {
private const string pageUrl = DemoRouteConstants.Demos_PieChart;
private const string pageTitle = "Pie Chart";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<PieChart @ref="pieChart" Width="600" OnClick="HandleClickAsync" />

@if (selectedChartItem is not null)
{
<p class="mt-3 mb-0">
Selected: @selectedChartItem.DatasetLabel (dataset @selectedChartItem.DatasetIndex), @selectedChartItem.Label (index @selectedChartItem.Index), value @selectedChartItem.Value
</p>
}

@code {
private PieChart pieChart = default!;
private PieChartOptions pieChartOptions = default!;
private ChartData chartData = default!;
private ChartClickEventArgs? selectedChartItem;

protected override void OnInitialized()
{
chartData = new ChartData
{
Labels = new List<string> { "Desktop", "Tablet", "Mobile" },
Datasets = new List<IChartDataset>
{
new PieChartDataset
{
Label = "Sessions",
Data = new List<double?> { 62, 18, 20 },
BackgroundColor = new List<string> { "#4BC0C0", "#9966FF", "#FF9F40" },
},
},
};
pieChartOptions = new PieChartOptions { Responsive = true };
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
await pieChart.InitializeAsync(chartData, pieChartOptions);

await base.OnAfterRenderAsync(firstRender);
}

private Task HandleClickAsync(ChartClickEventArgs eventArgs)
{
selectedChartItem = eventArgs;
return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
<Demo Type="typeof(PolarAreaChart_Demo_01_Examples)" Tabs="true" />
</Section>

<Section Class="p-0" Size="HeadingSize.H4" Name="Click event" PageUrl="@pageUrl" Link="click-event">
<Block>
Set the <code>OnClick</code> callback to react when a polar-area segment is selected. The callback receives <code>ChartClickEventArgs</code> with the dataset, item index, label, and raw value; the demo displays the selected item below the chart.
</Block>
<Demo Type="typeof(PolarAreaChart_Demo_02_Click_Event)" Tabs="true" />
</Section>

@code {
private const string pageUrl = DemoRouteConstants.Demos_PolarAreaChart;
private const string pageTitle = "PolarArea Chart";
Expand Down
Loading
Loading