Vaadin Charts. Click Listening: absolute value to chart axis value

Hello, guys! ChartClickEvent contains xAxisValue and absoluteX, but I want to click above the chart and get xAxisValue from absolute x value. if this is impossible, then other question: how to catch mouse down, mouse up events on the chart?

Thanks.

Hi Vitaly!

(Referring to the other question)
You could create an extension for the Chart for this purpose. This means that you would essentially need on the server side:

ChartExtension extends AbstractExtension implements ChartExtensionServerRpc{
  ...
    public ChartExtension() {
        registerRpc(this); 
    }

    public void extend(Chart chart) {
        super.extend(chart);
    }
 ...
}

On the client side, you would need a Connector and define the ServerRPC:
ChartExtensionServerRpc:

public interface ChartExtensionServerRpc extends ServerRpc { ... your methods ... }

ChartExtensionConnector:

@Connect(ChartExtension.class)   // Connect to your extension you created
public class ChartExtensionConnector extends AbstractExtensionConnector {
...
    @Override
    protected void extend(ServerConnector target) {
        final Widget extendedWidget = ((ComponentConnector) target).getWidget();
          // example with mouseDownhandler
        MouseDownHandler mdh = new MouseDownHandler() {

            @Override
            public void onMouseDown(MouseDownEvent event) {
                // This will call your method on the server side with your specified parameters
                getRpcProxy(ChartExtensionServerRpc.class).yourDefinedMethod(event.getClientX()); // For example the clientX
            }
        };
        // Store the handle to  be able to call removeHandler when needed
        mouseDownHandlerRegistration = extended.addDomHandler(mdh, MouseDownEvent.getType());
    }

And then in your app (after widgetset compilation or in dev mode) you can simply use your extension like this (for example):

    Chart c = new Chart(ChartType.PIE);
    new ChartExtension.extend(c);
    addComponent(c);