Jawbone / JBChartView

iOS-based charting library for both line and bar graphs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Show dot only on vertical line selection

nico75005 opened this issue · comments

commented

Is there a way to show the dot only on the vertical line selection?

I assume you mean to only show a dot when there is a selection on that particular data point?

Yes.

Implement:

- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
{
    // return color of dot on selection
}

and:

- (UIColor *)lineChartView:(JBLineChartView *)lineChartView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
{
    return [UIColor clearColor]; // hide all dots during non-selection
}

Hope this helps.

commented

Thanks Terry, that's indeed what I meant. I did that but I got all the dots on selection as I cannot find a way to get the index on the selection. The method

- (void)lineChartView:(JBLineChartView *)lineChartView didSelectLineAtIndex:(NSUInteger)lineIndex horizontalIndex:(NSUInteger)horizontalIndex;

is called after

- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex

so I don't know how to get the selected horizontalIndex by the time I return the dot color for the selection.

You're model should be structured in a way for you to supply the desired 'styling' for a given index.

I'm not sure how else I can help - the functionality is exposed for you to achieve the desired effect, you just need to access your model to get the information required.

commented

There is something I'm missing obviously.

Let's say I have on line chart with 10 value [1, 2, 3, 4, 5, 6, 7, 8, 9, 0].

What I would like to achieve is when I tap with my finger on the value let's say 4, only the dot on of my line for the value for will appear. I don't want any special style, just the same style for all the dots, just that the dot appears only on its selection like this screenshot:

screen shot 2015-10-22 at 15 20 34

From what I could see,

- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex

is called once for every value of my line chart per touch. So to hide or show the dot on selection, I need to be able to match the "horizontalIndex" of this method with the index of the current selection. How do I get this index? Like is there a method that, when I touch the screen on the chart, will give the current selection index?

Thanks for your patience with we anyway :)

Oh I get it. I'm sorry I misinterpreted what you wanted to do.

Unfortunately that's not possible with the current set of API's.

commented

Ahah too bad, I started to have some hopes for it.

Any hint where I should look in your library to implement it myself? I'm a swift guy, but I can read objective-c. Or I might try to do it directly in my project. Thanks anyway.

Yeah the logic would have to reside in:

touchesBeganOrMovedWithTouches

of JBLineChartView.

There you have pretty much all the information you need. You could iterate over all the dots in the dot view and just hide/show the one closest to the horizontal index your touch is at.

Hope this helps.

commented

Awesome I made it. Thanks a lot!

Awesome! No prob.