-
-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calculating space (in px) between two points #548
Comments
Here's the code I took from let valueToPixelMatrix = transformer.valueToPixelMatrix
for (var i = _minX, maxX = min(_maxX + 1, _xAxis.values.count); i < maxX; i += _xAxis.axisLabelModulus)
{
let label = _xAxis.values[i]
if (label == nil)
{
continue
}
position.x = CGFloat(i)
position.y = 0.0
position = CGPointApplyAffineTransform(position, valueToPixelMatrix) We use valueToPixelMatrix and other functions in ChartViewPortHandler to convert data value to px. So you should be able to calculate the space using these functions. |
But be careful, if you also enable the zooming feature, because the spaces can be amplified. |
Thank you @liuxuan30 , I finally managed this. However, is there a way to have the "position" variable of xAxisRenderer from outside the library (like a getter or something else) ? It would be the best way to have to coordinate of all the CGPoint. |
@jibax I'm afraid there is no such way to get it right now. Since this is not everyone asked to have. I do need the coordinate as well, but I write a delegate to get it. So if people are keeping asking for this, it can be implemented. But for now you have to write your own code to get it. |
Oh ok I get it. Thanks for the informations |
Hello @liuxuan30 and @jibax, I found this topic closed but I need the same coordinate as well for my app. I don’t want to ask you to commit but would it be possible to share the delegate you wrote here ? Thank you very much |
It depends on if you need the highlighted coordinates or all the points? There are several ways to do it, but needs you add some new functions and override some methods. For me I only need the highlighted one, so you can write a function called internal func getHighlightPoint, and take a look at how we get the highlighted point in The point is to know when you get the correct coordinates no matter in I add a delegate called |
Hi @liuxuan30 I did a delegate and it works pretty well. But the thing is I modify a Pod file ( ChartXAxisRenderer ) , it means it is gonna be delete on the next update. What should I do to keep this protocol for the next update? (I'm not used to modify pod) Thank you |
I am no expert of pod, @petester42 can help on this. |
You should never change the library cause it will overwrite your changes when you run pod install. Subclass is the way to go. Otherwise if it makes sense to be in the library then create a pull request with your work. |
Hi @petester42 Thank you for your answer. Problem is , I cannot subclass ChartXAxisRenderer because I got the following error "Multiple Inheritance from classes 'UIViewController' and 'ChartXAxisRender' which is pretty bad for me. So the only way to do this is to create a pull request right ? |
No. You can make a separate object that does only the chart axis rendering and then use that in your view controller. |
The thing is, I need to call (or even better override) the drawlabels function which has an internal accessibilty : so I'm not able to perform myChartAxisRenderingObject.drawlabels in my View controller. How can I do ? |
drawLabel is not called outside, it is called in chart view's drawRect. You can subclass the renderer, override drawLabels, and that's it. You don't have to call it. |
Hi,
I would love to display the value of the chart like below (instead of value). The thing is, I don't know how to deal with the coordinate of each point (xAxis). I searched a lot to get the space between two points (spaceBetweenLabel doesn't fit because it isn't a px value) in order to make a calculation. The label Value change when it goes over a point.
All I have is :
Is there a way to know the coordinate of each point, based of the UIView where the LineChart is displayed? Which value should I need to have to perform this ?
The red square is my lineChartView, the green one an UIScrollView where the user can scroll to display the chart.
Thanks a lot
The text was updated successfully, but these errors were encountered: