amcharts / amcharts5

The newest, fastest, and most advanced amCharts charting library for JavaScript and TypeScript apps.
Other
345 stars 92 forks source link

Adding button with tooltip of valueAxis stock chart #1663

Closed workingbuddy10 closed 1 month ago

workingbuddy10 commented 1 month ago

I am using the stock chart, where there is a movable tooltip with cursor on dateAxis and valueAxis.

Just adjacent to that I want to add a button too, and on clicking that we will create/initiate a horizontal line. This helps to create more accurate levels, at that price.

My concern is :

Codepen : https://codepen.io/Ansh-m-the-reactor/pen/JjQyrqB

How can we add a button ? Like this : image

I just want a sticky button on the container of the tooltip of the valueAxis.

martynasma commented 1 month ago

I suggest using built-in buttons:

tooltip.setAll({
  layout: root.horizontalLayout
});

var button = tooltip.label.children.unshift(am5.Button.new(root, {
  //isMeasured: false,
  centerX: am5.p100,
  // width: 40,
  // height: 20,
  x: am5.p0,
  y: am5.p0,
  dx: -50,
  label: am5.Label.new(root, {
    text: "BT"
  })
}));

button.events.on("click", function() {
  console.log("Clicked");
});
workingbuddy10 commented 1 month ago

Did exactly what you said @martynasma , but the button is not appearing : The codepen : https://codepen.io/Ansh-m-the-reactor/pen/JjQyrqB

zeroin commented 1 month ago

You created a tooltip but did not assign it to valueAxis. So it's just an instance which is not used anywhere.

Try adding: valueAxis.set("tooltip", tooltip);

workingbuddy10 commented 1 month ago

Genius @martynasma & @zeroin it worked!!