diogobernardino / williamchart

Android Library to rapidly develop attractive and insightful charts in android applications.
5.1k stars 800 forks source link

Tooltip next to selected value #192

Closed Neocortexxx closed 7 years ago

Neocortexxx commented 7 years ago

Hello,

I really like this library and I hope you can help me out.

I am trying to set my tooltip right next to the selected value of my LineChart, but the Tooltip is alway way to far on the right and below my selected value. I tested Tooltip.setX(0) and Tooltip.setY(0) and the Tooltip landed in the middle of the chart.

Is there a way to place the Tooltip direktly next to my LineSet value? I found a way with LineChart.getData().get(0).getScreenPoints() to get the value on the same X-coordinate of my touch, but my tooltip is still not in place. Would be great, if there is an easy way to solve this.

The screenshot shows my custom tooltip on position X=0 and Y=0. I want to place the blue circle over the selected value of the LineSet.

Hope its not to special and everyone else can use the information too.

photo_2017-03-23_15-51-00

diogobernardino commented 7 years ago

Even if you manage to center it correctly, it will fail to display it when you click the most right entries of the line, because there won't be enough space in the parent view to display the whole tooltip.

I can imagine this being solved by allowing to define priorities, such as, try to align this corner, if not enough space align to the other tooltip corner. But ok, this isn't possible at the moment.

Neocortexxx commented 7 years ago

Maybe the problem is, that the point (0/0) is in the center of the chart. If the 0 point would be on the topleft corner there would be no problem, because all x/y-values from touchevents would fit into the charts coordinatesystem. Is there a way for you to change this?

diogobernardino commented 7 years ago

No, by default the tooltip is centered on top of the entry. One can manipulate this a little using Tooltip.setVerticalAlignment and Tooltip.setHorizontalAlignment.

Still, your approach won't work because your tooltip layout forces the entry to be at the top-left corner of your tooltip, inside this circle. If you imagine a click on the most right entry of the line, there will never be enough space to display the tooltip.