Skip to content

Added OnClick for charts #961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

yannikHoeflich
Copy link

This PR adds an OnClick attribute for all charts here is an example for a pie chart:

<PieChart  @ref="pieChart" Width="500" OnClick="Clicked" />

@code{
    // Other stuff

    private void Clicked(string labelName){
        Console.WriteLine($"Clicked on: ${labelName}");
    }
}

The parameter for the event is the label name, sadly there is not really a better option.

@yannikHoeflich
Copy link
Author

I updated it to use the new ChartClickArgs. Now you can get the label name and index. So now it looks more like this:

<PieChart  @ref="pieChart" Width="500" OnClick="Clicked" />

@code{
    // Other stuff

    private void Clicked(ChartClickArgs args){
        Console.WriteLine($"Clicked on: {args.LabelName} with index {args.Index}");
    }
}

@gvreddy04
Copy link
Contributor

@yannikHoeflich Thank you for your time and the pull request. I'll take care of it.

@gvreddy04 gvreddy04 added this to the 3.4.0 milestone Feb 20, 2025
@bbm-design
Copy link

bbm-design commented Mar 20, 2025

tried your fork and got this error when trying the bar chart

Uncaught TypeError: can't access property "invokeMethodAsync", dotNetHelper is undefined
onClick http://localhost:5156/_content/Blazor.Bootstrap/blazor.bootstrap.js:1129
d http://localhost:5156/assets/plugins/global/plugins.bundle.js:46410
_handleEvent http://localhost:5156/assets/plugins/global/plugins.bundle.js:46416
_eventHandler http://localhost:5156/assets/plugins/global/plugins.bundle.js:46416
s http://localhost:5156/assets/plugins/global/plugins.bundle.js:46416
n http://localhost:5156/assets/plugins/global/plugins.bundle.js:46416
ct http://localhost:5156/assets/plugins/global/plugins.bundle.js:46410
ct http://localhost:5156/assets/plugins/global/plugins.bundle.js:46410

i have also seen that on multiple rows you have made reference to pie
even if the code concerns a different chart

example 

    window.blazorChart.bar.create(elementId, type, data, options, plugins);
    chart = window.blazorChart.pie.get(elementId);

@yannikHoeflich
Copy link
Author

Sorry for the late response. I will take a look at it.

@yannikHoeflich
Copy link
Author

Sorry, I forgot to do some changes at the other charts. That should fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants