willdale / SwiftUICharts

A charts / plotting library for SwiftUI. Works on macOS, iOS, watchOS, and tvOS and has accessibility features built in.
MIT License
837 stars 103 forks source link

Tap delegate is there? #235

Open AakashGeidea opened 1 year ago

AakashGeidea commented 1 year ago

Hi @willdale , Is there any delegate or call back methods available so that i can get value whenever user touches any point on graph? I want that whole data object corresponding to that touch. Highly appreciated your help.

iAugux commented 1 year ago

@AakashGeidea you can take advantage of ChartData's touchedDataPointPublisher

data.touchedDataPointPublisher
    .sink {
        print($0)
    }
    .store(in: &cancellables)

Outputs:

LineChartDataPoint(id: 15FC802F-B374-40F1-B0A3-AED4C34AA9B9, value: 13000.0, xAxisLabel: Optional("T"), description: Optional("Tuesday"), date: nil, pointColour: nil, ignoreMe: false, legendTag: "Test One")
LineChartDataPoint(id: 15FC802F-B374-40F1-B0A3-AED4C34AA9B9, value: 13000.0, xAxisLabel: Optional("T"), description: Optional("Tuesday"), date: nil, pointColour: nil, ignoreMe: false, legendTag: "Test One")
LineChartDataPoint(id: D9902CBC-1FFC-4FC3-80FB-B26A4FE312BE, value: 8000.0, xAxisLabel: Optional("W"), description: Optional("Wednesday"), date: nil, pointColour: nil, ignoreMe: false, legendTag: "Test One")
LineChartDataPoint(id: D9902CBC-1FFC-4FC3-80FB-B26A4FE312BE, value: 8000.0, xAxisLabel: Optional("W"), description: Optional("Wednesday"), date: nil, pointColour: nil, ignoreMe: false, legendTag: "Test One")