Charts: Using image as marker in the chart

Created on 19 Oct 2015  路  8Comments  路  Source: danielgindi/Charts

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?

Most helpful comment

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.

馃コ

All 8 comments

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()
    }

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

Thanks,
Gal

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.

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

answered in #506

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

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

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.

馃コ

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JW00332 picture JW00332  路  4Comments

Bharati555 picture Bharati555  路  4Comments

brytnvmg picture brytnvmg  路  4Comments

kwstasna picture kwstasna  路  3Comments

coop44483 picture coop44483  路  3Comments