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

Using image as marker in the chart #483

Closed
gal-orlanczyk opened this issue Oct 19, 2015 · 8 comments
Closed

Using image as marker in the chart #483

gal-orlanczyk opened this issue Oct 19, 2015 · 8 comments

Comments

@gal-orlanczyk
Copy link

Hi i am trying to find a way to make a data set that each of the markers will be an image instead of the default points or circles, is there a way to do it?

@liuxuan30
Copy link
Member

sure, there is already an UIImage property there:

public class ChartMarker: ChartComponentBase
{
    /// The marker image to render
    public var image: UIImage?

All you have to do is to figure out what's the position for it:

    /// Draws the ChartMarker on the given position on the given context
    public func draw(context context: CGContext, point: CGPoint)
    {
        let offset = self.offset
        let size = self.size

        let rect = CGRect(x: point.x + offset.x, y: point.y + offset.y, width: size.width, height: size.height)

        UIGraphicsPushContext(context)
        image!.drawInRect(rect)
        UIGraphicsPopContext()
    }

@gal-orlanczyk
Copy link
Author

Can you provide an example I can't find any in the documentation and I couldn't understand your explanation.

Thanks,
Gal

@liuxuan30
Copy link
Member

I am saying ChartMarker already has image property. I have post the code and point out the function in my answer that you need look at.

@gal-orlanczyk
Copy link
Author

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.
i really appreciate any help.

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

@liuxuan30
Copy link
Member

answered in #506

@vinhqn
Copy link

vinhqn commented Sep 27, 2017

Hi.
i want add marker using draw or property image same attachment file. help me. Thanks
screen shot 2017-09-27 at 3 45 46 pm

@NallapatiMalleswari
Copy link

Any one found solution for custom marker Image.
i want to add custom marker like in the bellow picture , anyone can help me. Thanks

screen shot 2017-10-31 at 3 20 08 pm

@waleedmahmood
Copy link

I don't know if anyone still looking for a solution. Here is an example:

let entries = stride(from: 0.0, to: Double(10), by: 1.0).map { (i) -> ChartDataEntry in
            return ChartDataEntry(x: i+0.25, y: Double(55), icon: UIImage.init(named: "YourImageName"))
        }

I am using scatter plot, just create your data entries with an image name, and Charts will plot it for you automatically, depending on icon size of your file.

🥳

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

5 participants