apexcharts.js icon indicating copy to clipboard operation
apexcharts.js copied to clipboard

Clickable annotations

Open placid2000 opened this issue 2 years ago β€’ 6 comments

Summary

Making annotations clickable and knowing which annotation by getting for example its xaxis index and/or timestamp would be very handy for some use cases.

API Changes

For example introduce an event called annotationClick() which allows to access different properties of that annotation as well as its y or x axis index or timestamp to be able to identify them.

Intended Use Case

There are anomalies marked with annotations. A click would allow to validate them or add some additional text information.

placid2000 avatar Mar 09 '22 14:03 placid2000

This would be extremely useful

ampodobas avatar Mar 16 '22 23:03 ampodobas

This would be great- there seems to already be handlers for mouseEnter and mouseLeave, so it'd be super nice if there was a mouseClick one as well to allow for a popup to show

image

trylaarsdam avatar May 09 '22 19:05 trylaarsdam

Actually just realized you can grab the event of a click on any part of the chart using this handler to accomplish this functionality (example in vue2):

var options = {
  chart: {
    events: {
      click: function (e, ctx, options) {
        // check e.target here
        console.log(e.target.innerHTML) // logs the content of the annotation, could be cross referenced with a separate list of annotations to get more info, etc.
      }
    }
  },
}

trylaarsdam avatar May 09 '22 19:05 trylaarsdam

@trylaarsdam The problem is that you cannot easily get the annotation context through the chart click event.

@junedchhipa would it be a problem to add the following to PointsAnnotation.js?

if (anno.click) {
    point.node.addEventListener(
        'click',
        anno.click.bind(this, anno)
    )
}

I think this would be extremely useful, and would be happy to open a PR for it.

robyedlin avatar Jun 18 '22 04:06 robyedlin

Yeah agreed, that would be nice.

I believe I just included a short ID in the text of the annotation to determine which one was clicked, but that is a bit of a bodge

trylaarsdam avatar Jun 18 '22 05:06 trylaarsdam

It’s also possible to add a meaningful class to the marker or label, but not the image.

robyedlin avatar Jun 18 '22 15:06 robyedlin

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Aug 19 '22 14:08 github-actions[bot]

I'd like for this to remain open since #3318 doesn't fully address the issue because it only adds a click handler for x-axis labels.

trylaarsdam avatar Aug 21 '22 01:08 trylaarsdam

Since v3.35.4, click events on annotations are added. The y-axis and the x-axis annotations have click events on their labels, while the point annotations have click events on the marker as well as the label. Here are the docs - https://apexcharts.com/docs/options/annotations/

junedchhipa avatar Aug 23 '22 13:08 junedchhipa