Skip to content
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

Datapoint selection callback in Java #176

Open
Mastermori opened this issue Mar 2, 2024 · 1 comment
Open

Datapoint selection callback in Java #176

Mastermori opened this issue Mar 2, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Mastermori
Copy link

Mastermori commented Mar 2, 2024

Is your feature request related to a problem? Please describe.
I can currently find no way to add a DataPointSelect callback to a chart. The EventsBuilder only accepts javascript code in the form of Strings.

Describe the solution you'd like
A withDataPointSelection() method that allows me to call a metho in Java.

Describe alternatives you've considered
I have found no way to call java code from javascript.

Additional context
/

@Mastermori Mastermori added the enhancement New feature or request label Mar 2, 2024
@Scarlethue
Copy link

There is a workaround for this that works for me. Make sure to pass the getId() of the view as the elementId.

In View:

@ClientCallable
public void handleChartClickEvent(int seriesIndex, String seriesName, int dataPointIndex, String categoryLabel, double value, int mouseX, int mouseY) {
     // do something
}

In Chart:

private String getCallback(String elementId) {
        String function = """
                function(event, chart, selected) {
                    var element = document.getElementById("%s");
                    console.log(selected);
                    element.$server.handleChartClickEvent(
                        selected.seriesIndex,
                        chart.w.config.series[selected.seriesIndex].name,
                        selected.dataPointIndex,
                        selected.w.globals.categoryLabels[selected.dataPointIndex],
                        selected.w.globals.series[selected.seriesIndex][selected.dataPointIndex],
                        event.clientX,
                        event.clientY
                    );
                }
                """;
        return String.format(function, elementId);
    }
.withEvents(EventsBuilder.get()
                        .withDataPointSelection(getCallback(elementId))
                        .build())

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

No branches or pull requests

2 participants