Tob
Tob

Reputation: 1025

How do you select/highlight a part of the chart through code? (Charts- PieChartView)

I am using these classes to make charts: https://github.com/danielgindi/Charts .I currently have a pie chart displaying two options and I was wondering how you would highlight one of the options programmatically.

Upvotes: 1

Views: 8423

Answers (2)

dimpiax
dimpiax

Reputation: 12697

Swift 4

Charts (3.1.1)

You can choose an entry manually by highlightValue function.

If you want to highlight (select) by touch point, for example using UILongPressureGesture, it's possible to retrieve a potential highlight from chart and apply to its highlightValue function .

...
let point = gesture.location(in: chart)
let highlight = chart.getHighlightByTouchPoint(point)
chart.highlightValue(highlight)

Upvotes: 3

RashmiG
RashmiG

Reputation: 318

You can use the following methods to highlight part of the chart through code.

- (void)highlightValues:(NSArray<ChartHighlight *> * _Nullable)highs;

This should be used to programmatically highlight values. This DOES NOT generate a callback to the delegate.

- (void)highlightValue:(ChartHighlight * _Nullable)highlight; 

highlight contains information about which entry should be highlighted.No call back to delegate.

- (void)highlightValueWithXIndex:(NSInteger)xIndex dataSetIndex:(NSInteger)dataSetIndex callDelegate:(BOOL)callDelegate;

/// Highlights the value at the given x-index in the given DataSet. Provide -1 as the x-index to undo all highlighting.

Examples :

 1. [_chartView highlightValue:[[ChartHighlight alloc] initWithXIndex:0 
    dataSetIndex:0]];
 2. [_chartView highlightValueWithXIndex:0 dataSetIndex:0
    callDelegate:YES];

Upvotes: 6

Related Questions