I have two questions about anychart.
(1) I have implemented drawing tools like below (except for "Label") with React and am wondering if it is possible to implement a functionality for "Label" with React, i.e. let user modify an existing label's text.
https://www.anychart.com/products/anystock/overview/ Drawing Tools And Annotations
(2) If I select (click on) an existing label, it seems getSelectedAnnotation() can't get the selected one. The following code is in React functional component, probably is this the reason of that?
chart.listen(`annotationSelect`, function (e) {
if (e.annotation.type === `label`) {
console.log(e.annotation) // this prints e.annotaion object
const s = chart.annotations().getSelectedAnnotation()
console.log(s) // this prints "null"
}
})
A1 - you can implement any logic you need to modify the label annotation and UI approach. The library has all the required API. For example, you can listen for keyboard inputs in the hidden text area and apply text to the label. For details, check the live sample. Simply select the label and start typing the text. A similar approach is used in the demo app.
A2 - You need to wait until the next round of the JS event loop. For example, with setTimeout with zero time to schedule a task on the next round. Here is the modified sample.