Skip to content

Add chart item click event handling and enhance JavaScript interop#37

Merged
gvreddy04 merged 6 commits into
mainfrom
features/chart-click-event-support
Jul 14, 2026
Merged

Add chart item click event handling and enhance JavaScript interop#37
gvreddy04 merged 6 commits into
mainfrom
features/chart-click-event-support

Conversation

@gvreddy04

Copy link
Copy Markdown
Collaborator

This pull request adds support for chart data item click events across all chart types in the BlazorExpress.ChartJS library. It introduces a new OnClick callback that provides detailed information about the selected chart item, updates the JavaScript interop to bridge click events from Chart.js to .NET, and includes tests and documentation for the new feature.

New Chart Click Event Support:

  • Added a new ChartClickEventArgs class to encapsulate metadata about the clicked chart item, including dataset index/label, data item index/label, and value.
  • Introduced an [Parameter] OnClick callback to ChartComponentBase, invoked when a chart data item is selected. The callback receives a ChartClickEventArgs instance.
  • Implemented the click event bridge in JavaScript (blazorexpress.chartjs.js), wiring up canvas click events to call the .NET handler with the correct metadata.

Interop and Component Updates:

  • Updated all chart component InitializeAsync methods to pass a DotNetObjectReference for click event interop.
  • Ensured proper disposal of the DotNetObjectReference in ChartComponentBase to avoid memory leaks.

Demo, Documentation, and Testing:

  • Enhanced the Bar Chart demo to showcase the new click event, displaying selected item details on click.
  • Added a documentation section explaining the click event feature.
  • Added comprehensive tests for the click event bridge and callback behavior.

Other:

  • Updated global usings for System.Text.Json.

These changes allow developers to easily react to user interactions with chart data points, enabling interactive dashboards and data exploration scenarios.

Introduced `DotNetObjectReference` in `ChartComponentBase` and updated all chart components to handle click events on chart data items. Added `HandleClickAsync` method and `OnClick` parameter for callback support. Implemented `ChartClickEventArgs` to encapsulate click metadata.

Enhanced JavaScript interop in `blazorexpress.chartjs.js` to attach click handlers and dispatch events to .NET. Updated `Dispose` method to clean up resources. Added versioning and descriptions for new features.
@gvreddy04 gvreddy04 added this to the 1.2.4 milestone Jul 14, 2026
@gvreddy04 gvreddy04 self-assigned this Jul 14, 2026
@gvreddy04 gvreddy04 added the enhancement New feature or request label Jul 14, 2026
Removed the `ChartClickEventArgsTests` class and its test methods, including `HandleClickAsync` tests and JavaScript bridge validation. Deleted the `GetRepositoryFile` helper method and the `TestChartComponent` class. Cleaned up unused `using` directives and namespace declaration.
@gvreddy04 gvreddy04 linked an issue Jul 14, 2026 that may be closed by this pull request
Added a new namespace declaration `BlazorExpress.ChartJS.Demo.RCL`.
Introduced a `<Section>` component for the "Prerequisites" section.
Included a `<Block>` with a link to the "Getting Started guide".
Added a `PageUrl` parameter for dynamic URL handling.
Added "Click event" sections to documentation for BarChart,
BubbleChart, DoughnutChart, LineChart, PieChart, PolarAreaChart,
RadarChart, and ScatterChart. These sections explain the use of
the `OnClick` callback to handle user interactions with chart
elements.

Created new demo files for each chart type to showcase the
"Click event" functionality. Demos include event handling,
chart data initialization, and displaying selected item details.
@gvreddy04 gvreddy04 merged commit 86d053a into main Jul 14, 2026
1 of 2 checks passed
@gvreddy04 gvreddy04 deleted the features/chart-click-event-support branch July 14, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Click event support

1 participant