Skip to content
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

Making a line chart set with images on the chart #506

Closed
gal-orlanczyk opened this issue Oct 26, 2015 · 6 comments
Closed

Making a line chart set with images on the chart #506

gal-orlanczyk opened this issue Oct 26, 2015 · 6 comments

Comments

@gal-orlanczyk
Copy link

i want to make a graph like this where 1 set will be a regular line and the other will be another indicator with pills for example if my x axis is the time i will have a series of times i need to take a pill.
i don't need the marker to show image when it is selected i need a complete set of data values to show images instead of default circle/dot. in short i need to create a series of images instead of the default dots/circles for a set of data.
i really appreciate any help.

screenshot:
screen shot 2015-10-26 at 08 20 49

@liuxuan30
Copy link
Member

Then write your own code and logic to add the image. The logic to calculate the position is already there. You simply write your own rendering method to draw the images instead of line dots

@gal-orlanczyk
Copy link
Author

Listen i really don't understand what you mean, could you please provide me with a little example...
where is the drawing method of the dots that i can override with my own drawing? i am really lost here and could really use your help...

@liuxuan30
Copy link
Member

I have no time to provide code example. You should have the knowledge and skill to code right?

Where to draw the dot: search private func drawCircles(context context: CGContext)
This is where it draws the circle. walk through the logic to have a better idea and sub class of line chart view and override this method, to draw the image you want

It has calculated the position with pt = CGPointApplyAffineTransform(pt, valueToPixelMatrix)

What you need to do is simply have your image ready and put the image at position pt

@gal-orlanczyk
Copy link
Author

the drawCircles is in the renderer, i can't get it to subclass properly. i understand i can only switch the renderer of the chart and than it will draw the images but i can get it subclass from outside the library.
is there an example of subclassing the renderer properly? (the animator property doesnt get recognised)

@liuxuan30
Copy link
Member

you have to sub class the chart view and replace the renderer with yours. You are making customizations so expect a desent change and sub-class stuff will happen in your project, basically you will need to sub class everything you need to change. To me I think only sub class chart view and its renderer should be enough, and if you want more different images, sub class the dataSet and fill any image you want is also possible

Take a look at how bar chart and line chart is sub classed from BarLineChartViewBase

@AlexanderKvamme
Copy link

AlexanderKvamme commented Apr 25, 2017

Hey guys I am curious about this as well! All i wanna do is to fill a select few holes. Im very new to customizing libraries, and im wondering, is this possible to to do without manipulating the Charts files? Im using Cocoapods and im wondering if i can do this with subclassing or if i gotta manually drag the Charts files over and then manipulate them :) I tried modifying like this:

//class MyLineChartRenderer:
extension LineChartRenderer {

but both are telling me '_xBounds' is inaccessible due to 'internal' protection level. If I can get access to the variables i can probably manage the rest by myself. But I have found very little info about modifying frameworks online :)

EDIT: For anyone wondering, I ended up manually adding the framework to my project so that i could access the values i needed. I duplicated LineChartRenderer, calling the new one CustomLineChartRenderer, and made my customization through a global variable, and made sure to make LineChartView call CustomLineChartRenderer, and not the regular LineChartRenderer. Worked great! If anyone has a better way of doing this with cocoapods I would love to know :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants