2

I have a CombinedChart in my app (same app on both Android and iOS platforms using MPAndroidChart & iOS-Charts respectively) with stacked bars and a line but I also need to highlight specific points where a given event happened. I've got some small icon images (png) and need to place the correct image at the correct place on the graph depending on what type of event happened. I have tried Bubble chart first and can get bubbles of the right colour at the right location but can't specify custom image instead of the bubbles' circles.

I am now trying Scatter Chart which does have a Custom shape option but it's not just a shape I need, it's a specific image. I have not worked with Core Graphics before so I'm not familiar with CGPath functions.

Is there a way to pass a UIImage to the ScatterChart customScatterShape property? Or maybe a way to convert a UIImage created from a named png to a CGPath object which the Scatter Chart custom shape requires?

Thanks in advance for your suggestions!

Litome
  • 653
  • 8
  • 12
  • I've tried to convert an SVG to a CGPath using [this](https://jeffmenter.wordpress.com/2011/04/17/method-for-interpreting-illustrator-art-assets-as-cocoa-cgpathref/) and set the resulting CGPathRef as the customScatterShape of my ScatterChartDataSet. But the scatter plots don't show anymore. Note that if I use a basic shape (say Triangle) for the same set, it does show. – Litome Apr 01 '16 at 13:57
  • I found a simple SVG that could be reliably converted to CGPath and that displays so I'll continue trying to convert my icons to SVG and then to CGPath. But if anybody has any hint for a way to give a UIImage to display at a given set of coordinates on the chart, I'd love to know about it! please... – Litome Apr 01 '16 at 22:17
  • If anybody is struggling with the same, here are a few pointers: [StackOverflow question 3549124](http://stackoverflow.com/questions/3549124/how-to-create-a-cgpath-from-a-file-i-e-svg). Look for @GlenHowes answer. [SVGgh library on GitHub](https://github.com/GenerallyHelpfulSoftware/SVGgh) and [Ryan's App Blog post](https://rdsquared.wordpress.com/2012/01/10/svg-to-coregraphics-conversion/) giving an actual SVG that does convert to CGPath and tips on how to massage the SVG data to get to something that can be converted. – Litome Apr 01 '16 at 22:20

1 Answers1

3

As of MPAndroid version 3.0.2, you can pass in a Drawable as part of your Entry dataSet.add(new Entry(x, y, drawable)), and enable the drawIcons flag via dataSet.setDrawIcons(true).

Source code where icon gets drawn for Line charts specifically: LineChartRenderer.java

jolima
  • 56
  • 2
  • In addition to this, I couldn't get the dataset's `ScatterShape` items to disappear, so I changed their size to smaller than my drawable (something like 0.5): `scatterShapeSize = 0.5f` – ConcernedHobbit Oct 07 '21 at 19:49