Overlay in a LineChart - get the exact y position when using a double
See original GitHub issueI’m displaying a LineChart
with curve type set to curveMonotoneX
inside a ScrollView
, I want to animate an overlay when the user is scrolling the ScrollView, I’m calculating the percentage of an item, then I send the double value to the x
function.
E.g. index 14 becomes 14.23, when I send it to the x
function I get the exact position within the chart.
This works fine, but whenever I send in the double to the y
function I get some weird return value, does the y function support doubles?
As you can see in the screenshot the overlay is misplaced, for some reason it has the wrong y position, (see the yellow arrow), it should actually be located where the green arrow is pointing.
Here’s the code I’m using
private readonly Tooltip = ({ x, y }) => {
const { indexOfActiveDataPoint } = this.state; /* e.g 14.23 */
const xA = x(indexOfActiveDataPoint) - (75 / 2);
const yA = y(this.state.data[Math.floor(indexOfActiveDataPoint)].current ? this.state.data[Math.floor(indexOfActiveDataPoint)].current._value : this.state.data[Math.floor(indexOfActiveDataPoint)]);
console.log(xA, yA);
return (
<G
x={xA}
key={"tooltip"}
>
<G x={75 / 2}>
<Circle
onPressOut={() => console.log("tooltip clicked")}
cy={yA}
r={5}
strokeWidth={1}
fill={"rgba(255,255,255,0.5)"}
/>
</G>
</G>
);
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
How to overlay the x and y axis on top of line chart using ...
1 Answer 1 ... You can setPosition(YAxisLabelPosition pos): Sets the position where the axis-labels should be drawn. Either INSIDE_CHART or ...
Read more >A Complete Guide to Area Charts | Tutorial by Chartio
Area charts combine the line chart and bar chart for more specific purposes. Use this guide to learn the best times and ways...
Read more >Excel Chart: Fill Area under the XY Chart and ... - YouTube
In this tutorial, I have explained how to fill the area under the XY Chart and between XY Chart with simple steps.
Read more >Shade the Area Between Two Lines - Excel Line Chart
We then tidy up the chart by replacing the Legend with an alternative way of differentiating the two lines. Find more great free...
Read more >Line chart options | Looker - Google Cloud
Charts with the Series Positioning option set to Grouped or Overlay can have multiple y-axes. Any Stacked or Stacked Percentage charts will have...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Also in order to correctly troubleshoot I need a complete, small example. This example provides me with very little to go on (code wise). Great screenshot though
Closing due: