Can I handle faucet events in a BarChart column?

I know that on MPAndroidChart you can handle events in diagrams. In the documentation, all documents are well documented.

However, I can not find the documentation of the same events on ios-chart . I know that its creator says that we should follow the MPAndroidChart document for its library, but I cannot handle these events in Swift 3.0.

I also could not find any examples of handling these events for the ios-chart library.

So, is it possible to handle the click event in the ios-chart library?

EDIT: According to @AdamM reviews @AdamM I'm going to include a function here in which I set the data in a chart.

 func enterData(valuesChart: [BarChartDataEntry]){ let chartDataSet = BarChartDataSet(values: valuesChart, label: "Total Values") let charData = BarChartData(dataSets: [chartDataSet]) barChartView?.data = charData barChartView?.animate(xAxisDuration: 2.0, yAxisDuration: 2.0) } 

Thanks in advance!

+6
source share
2 answers

Yes, this functionality is built into the graphics library. Make sure your class complies with the ChartViewDelegate protocol.

Change sample full code

 import UIKit import Charts @objc(BarChartFormatter) public class BarChartFormatter: NSObject, IAxisValueFormatter { var months: [String]! = ["Jan", "Feb", "Mar"] public func stringForValue(_ value: Double, axis: AxisBase?) -> String { return months[Int(value)] } } class ViewController: UIViewController,ChartViewDelegate { @IBOutlet var barChart : BarChartView! let dataArray = ["Jan", "Feb", "Mar"] override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. self.title = "Testing" let values = [5.2,10.5,15.3] setBarChart(values: values) barChart.delegate = self } //MARK: Chart delegate methods func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) { let pos = NSInteger(entry.x) print(dataArray[pos]) } func chartValueNothingSelected(_ chartView: ChartViewBase) { } //MARK: Set chart func setBarChart(values: [Double]) { var dataEntries: [BarChartDataEntry] = [] for i in 0..<values.count { let dataEntry = BarChartDataEntry(x: Double(i), y: values[i]) dataEntries.append(dataEntry) } let dataSet = BarChartDataSet(values: dataEntries, label: "") var dataSets : [IChartDataSet] = [IChartDataSet]() dataSets.append(dataSet) let format:BarChartFormatter = BarChartFormatter() let xAxis = barChart.xAxis xAxis.granularity = 1.0 xAxis.labelPosition = .bottom xAxis.valueFormatter = format let chartData = BarChartData(dataSets: dataSets) barChart?.data = chartData } } 
+5
source

For iOS Charts 3. Omit dataSetIndex!

 func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {...} 
+1
source

Source: https://habr.com/ru/post/1011765/


All Articles