Incorrect pointIndex in trackball callback for last column with data

When using the nearestPoint TrackballDisplayMode the pointIndex for the last column of data is returning the incorrect index

    tooltipDisplayMode: TrackballDisplayMode.nearestPoint,
      builder: (BuildContext context, TrackballDetails trackballDetails) {
        return summaryBuilder(trackballDetails, context);
      },

e.g. in this chart there is non-zero data for the first twenty days in the 31 collection, selecting the first column will supply pointIndex 0 as expected:


Selecting 19th column supplies pointIndex 18: 


but selecting the 20th column supplies pointIndex 20:


Selecting 21st column supplies pointIndex 21 and so on


5 Replies

UD UdhayaKumar Duraisamy Syncfusion Team March 21, 2023 05:16 PM UTC

Hi David,


We have tried to reproduce the reported issue that is getting incorrect point index values in the trackball builder, but the issue is not reproduced at our end. We kindly request you share more information about the complete chart sample code snippet and data source used and also try to reproduce the reported issue in the shared sample below. It will be more helpful for to us assist you in a better way.


We have also shared the screenshot for your requirement.






Regards,

Yuvaraj.


Attachment: f181256_56b9b27b.zip


DB David Bacon March 23, 2023 11:00 AM UTC

I noticed from your screenshots you haven't selected the last column - that's where I'm seeing the issue.


Chart Code:

 child: SfCartesianChart(
            legend: Legend(isVisible: false, overflowMode: LegendItemOverflowMode.wrap),
            plotAreaBorderWidth: 0,
            primaryXAxis: createXAxis(),
            primaryYAxis: NumericAxis(
                plotBands: [
                  PlotBand(
                    start: 0,
                    end: 0,
                    borderColor: EncomColors.foregroundGradient,
                    borderWidth: 1,
                  )
                ],
                axisLine: const AxisLine(width: 0),
                edgeLabelPlacement: EdgeLabelPlacement.shift,
                labelFormat: '{value} ' + ('kW'),
                isVisible: false,
                majorTickLines: const MajorTickLines(size: 0)),
            series: getStackedColumnSeries(),
            tooltipBehavior: TooltipBehavior(enable: false, canShowMarker: false),
            trackballBehavior: TrackballBehavior(
              enable: true,
              markerSettings: const TrackballMarkerSettings(
                markerVisibility: TrackballVisibilityMode.hidden,
                height: 10,
                width: 10,
                borderWidth: 0,
              ),
              hideDelay: 3500,
              activationMode: ActivationMode.singleTap,
              tooltipAlignment: ChartAlignment.center,
              tooltipDisplayMode: TrackballDisplayMode.nearestPoint,
              builder: (BuildContext context, TrackballDetails trackballDetails) {
                return summaryBuilder(trackballDetails, context);
              },
              lineWidth: 1,
              shouldAlwaysShow: true,
            ),
          ),


 List<StackedColumnSeries<ReportReading, DateTime>> getStackedColumnSeries() {
    return <StackedColumnSeries<ReportReading, DateTime>>[
      getColumnSeriesForMeter(MeterName.consumptionPeak),
      getColumnSeriesForMeter(MeterName.consumptionOffPeak),
      getColumnSeriesForMeter(MeterName.consumptionBattery),
      getColumnSeriesForMeter(MeterName.consumptionPV),
    ];
  }


  StackedColumnSeries<ReportReading, DateTime> getColumnSeriesForMeter(MeterName meterName, [bool? negate]) {
    bool negateTotal = negate ?? false;
    return StackedColumnSeries<ReportReading, DateTime>(
        dataSource: widget.reportReadings[meterName]!,
        xValueMapper: (ReportReading reading, _) => reading.dateTime,
        yValueMapper: (ReportReading reading, _) => negateTotal ? reading.nonNullTotal * -1 : reading.total,
        color: meterName.color,
        name: meterName.displayName);
  }





YG Yuvaraj Gajaraj Syncfusion Team March 24, 2023 02:13 PM UTC

Hi David,


We are unable to reproduce the reported issue on our end. We suspect that you may have duplicate data in your data source. To resolve this, please check your data source and remove any duplicate data before assigning it.


If you continue to experience the same issue, please try to reproduce it using the sample that was previously shared with you.


Regards,

Yuvaraj.



DB David Bacon March 27, 2023 10:17 AM UTC

Hi Yuvaraj,


You are correct - the data was duplicated for that final entry, there was an entry with the real data which is displayed on the chart and then another entry with zero values which seems to be override it for the trackball. Sorting the data out has fixed the issue.


Thanks for your help and pointing me in the right direction.


David



YG Yuvaraj Gajaraj Syncfusion Team March 28, 2023 08:58 AM UTC

Most Welcome. Kindly get back to us if you have further queries. We are always happy to assist you.


Loader.
Up arrow icon