title: SwiftUI iOS CHARTS: How to get highlighted value
body: <p>Using iOS Charts (by Daniel Gindi <a href="https://github.com/danielgindi/Charts" rel="nofollow noreferrer">https://github.com/danielgindi/Charts</a>) and SwiftUI, I would like to get the selected value from a Line Chart, the highlighted value when the user tap it. The highlight is working, I can see the additional lines for this value.</p>
  <p>After some research, I found we have to create this function: chartValueSelected() but it's never called in this case. I suppose I have to deal with the delegate but I did not find any solution or example with SwiftUI. Can someone help ? Thanks
  <a href="https://i.stack.imgur.com/fTUuD.png" rel="nofollow noreferrer">LineChart</a></p>
  <pre><code>    import Foundation
      import Charts
      import SwiftUI
  
      struct GraphMeterLine : UIViewRepresentable {
      var xArray:[Float] = [0,1,2,3,4]
      var yArray:[Float] = [0,3,6,2,12]
      var data = LineChartData()
      let chartline = LineChartView()
  
          func makeUIView(context: Context) -&gt; LineChartView {
              return chartline
          }
  
          func updateUIView(_ uiView: LineChartView, context: Context) {
              //when data changes chartd.data update is required
              uiView.data = createGraph()
          }
      
      
      func createGraph() -&gt; LineChartData {
          var lineChartEntry = [ChartDataEntry]()
         
              for i in 0..&lt;yArray.count {
                  let value = ChartDataEntry(x: Double(xArray[i]), y: Double(yArray[i]))
                  lineChartEntry.append(value)
              }
              
          let line1 = LineChartDataSet(entries: lineChartEntry, label: &quot;Number&quot;)
          
  
          data.addDataSet(line1)
  
                  data.setDrawValues(false)
                  return data
      }
  
      public func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
          print(&quot;To Display Values X/Y Values here&quot;)
      }
      
          typealias UIViewType = LineChartView
          
      }
  </code></pre>