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

Any way to add/use image for xVals? #126

Closed
liebeskind opened this issue Jun 2, 2015 · 11 comments
Closed

Any way to add/use image for xVals? #126

liebeskind opened this issue Jun 2, 2015 · 11 comments
Labels

Comments

@liebeskind
Copy link

I am trying to have text and UIImage show up next to each other on the x axis of a bar chart. Any suggestions on how to do this?

@danielgindi
Copy link
Collaborator

There's currently no support for that. You can try adding it yourself in the XAxisRenderer - or adding those externally with UIImageViews, taking the correct coordinates from the ViewPortHandler

@liebeskind
Copy link
Author

Thanks Daniel. Is there any way to get an array of y coordinates for each xAxis line in a horizontal bar chart? I can then add UIImageViews to the Superview to externally place them at the .Top of each line.

I can't figure out how to get those values with ViewPortHandler.

@danielgindi
Copy link
Collaborator

The viewport tells you were content is drawn.
Then you can use the tranformer to convert x values to pixels (those are
the positions for the labels).
And there are properties that tell you which x indexes are visible

‏בתאריך יום רביעי, 3 ביוני 2015, Daniel notifications@github.com כתב:

Thanks Daniel. Is there any way to get an array of y coordinates for each
xAxis line in a horizontal bar chart? I can then add UIImageViews to the
Superview to externally place them at the .Top of each line.

I can't figure out how to get those values with ViewPortHandler.


Reply to this email directly or view it on GitHub
#126 (comment)
.

@liebeskind
Copy link
Author

Any chance you have or know of any examples where this is done?

I know how to use the viewPort to get the content area using

barChartView.viewPortHandler.contentRect

but I am not sure how to get xAxis values or use the transformer to convert to pixels.

@danielgindi
Copy link
Collaborator

Give it a value of x=1,y=0 and it will convert that x to the proper pixel
value for xIndex 1. Same for 2 etc.

On Wed, Jun 3, 2015 at 6:44 PM, Daniel notifications@github.com wrote:

Any chance you have or know of any examples where this is done?

I know how to use the viewPort to get the content area using

barChartView.viewPortHandler.contentRect

but I am not sure how to get xAxis values or use the transformer to
convert to pixels.


Reply to this email directly or view it on GitHub
#126 (comment)
.

@liebeskind
Copy link
Author

Thanks Daniel - what method should I use on viewPortHandler to do this? What do I give a value of x=1, y=0 to?

@danielgindi
Copy link
Collaborator

The transformer, not the viewport. You need to ask the Chart to give you
the transformer

‏בתאריך יום רביעי, 3 ביוני 2015, Daniel notifications@github.com כתב:

Thanks Daniel - what method should I use on viewPortHandler to do this?
What do I give a value of x=1, y=0 to?


Reply to this email directly or view it on GitHub
#126 (comment)
.

@liebeskind
Copy link
Author

OK - I believe I've made a bit of progress. I set up the chart with:

var yVals: [BarChartDataEntry] = []
for idx in 0...numOptions {
        var index = "option\(idx)Votes"
        var votes = quest.objectForKey(index) as? Int
        if let vote = votes {
            yVals.append(BarChartDataEntry(value: Float(vote), xIndex: idx))
        }
    }

let set2 = BarChartDataSet(yVals: yVals, label: "Votes")
let dataBar = BarChartData(xVals: xVals, dataSet: set2)

Then I use ChartTransformer to generate values:

var somePoints = ChartTransformer(viewPortHandler: barChartView.viewPortHandler).generateTransformedValuesHorizontalBarChart(yVals, dataSet: 1, barData: dataBar, phaseY: 1.0)
println(somePoints)

[(1.0, 1.0), (1.0, 2.0), (1.0, 3.0), (1.0, 4.0)]

Then I try to convert the values to pixels:

ChartTransformer(viewPortHandler: barChartView.viewPortHandler).pointValuesToPixel(&somePoints)
    println(somePoints)

[(1.0, 1.0), (1.0, 2.0), (1.0, 3.0), (1.0, 4.0)]

It's clear that I'm doing something wrong, but feels like I'm on the right track. Thank you for your assistance so far - I continue to appreciate any guidance.

@liebeskind
Copy link
Author

Daniel, thanks for your help with this. Figured it out.

var imagePos = barChartView.getPosition(yVals[opt], axis: .Left)

(219.090912112191, 270.833333333333)

Can then pull the x and y with

imagePos.y
imagePos.x

This is great! Very cool functionality.

@walinaqvi
Copy link

Hi @liebeskind where did you add these images so it scroll along with bars of graph ?

@Gagan6696
Copy link

Can you guys please share the sample. So that it becomes easy to use

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

No branches or pull requests

4 participants