Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot give different trackball colors to Two RangeColumnSeries #2287

Open
Ashutosh-Rana opened this issue Feb 17, 2025 · 1 comment
Open
Labels
charts Charts component waiting for customer response Cannot make further progress until the customer responds.

Comments

@Ashutosh-Rana
Copy link

Use case

I want to show different trackball colors for each systolic and diastolic points when hovered but it is not happening.
Please find attached the screenshot for your reference.

Image

Proposal

return TrackballBehavior(
      enable: true,
      activationMode: ActivationMode.singleTap,
      tooltipDisplayMode: TrackballDisplayMode.groupAllPoints,
      tooltipAlignment: ChartAlignment.near,
      shouldAlwaysShow: true,
      lineColor: AppColors.grey.shade600,
      markerSettings: TrackballMarkerSettings(
        markerVisibility: TrackballVisibilityMode.visible,
        shape: DataMarkerType.diamond,
        height: 10,
        width: 10,
        borderWidth: 1,
        color: AppColors.status.shade700, // I want to make this color dynamic
        borderColor: AppColors.status.shade50,
      ),
      builder: builder,
    );
@VijayakumarMariappan VijayakumarMariappan added charts Charts component open Open labels Feb 17, 2025
@Baranibharathip
Copy link

Hi @Ashutosh-Rana,

We have reviewed your query and would like to inform you that you can achieve your requirement by using a custom trackballBehavior. By utilizing the onPaint method, you can draw a custom marker on the trackball line. We have provided a code snippet and demo for your reference.

@override
  Widget build(BuildContext context) {
    return SfCartesianChart(
        trackballBehavior: _TrackballBehavior(),
            ....
        

class _TrackballBehavior extends TrackballBehavior {
  @override
  bool get enable => true;

  @override
  ActivationMode get activationMode => ActivationMode.singleTap;

  @override
  TrackballDisplayMode get tooltipDisplayMode =>
      TrackballDisplayMode.groupAllPoints;

  @override
  TrackballMarkerSettings? get markerSettings => const TrackballMarkerSettings(
        markerVisibility: TrackballVisibilityMode.visible,
        shape: DataMarkerType.diamond,
        borderWidth: 1,
      );

  @override
  void onPaint(PaintingContext context, Offset offset,
      SfChartThemeData chartThemeData, ThemeData themeData) {
    if (chartPointInfo.isEmpty || parentBox == null) {
      return;
    }
    super.onPaint(context, offset, chartThemeData, themeData);
    final Paint fillPaint = Paint()..style = PaintingStyle.fill;
    const Size lineMarkerSize = Size(15, 15);
    final translatePos =
        Offset(-lineMarkerSize.width / 2, -lineMarkerSize.height / 2);
    if (chartPointInfo.isNotEmpty) {
      final int length = chartPointInfo.length;
      for (int i = 0; i < length; i++) {
        fillPaint.color = chartPointInfo[i].color!;
        // High position.
        Offset position =
            Offset(chartPointInfo[i].xPosition!, chartPointInfo[i].yPosition!);
        paint(
          canvas: context.canvas,
          rect: position.translate(translatePos.dx, translatePos.dy) &
              lineMarkerSize,
          shapeType: ShapeMarkerType.diamond,
          paint: fillPaint,
        );
        // Low position.
        position = Offset(
            chartPointInfo[i].xPosition!, chartPointInfo[i].lowYPosition!);
        paint(
          canvas: context.canvas,
          rect: position.translate(translatePos.dx, translatePos.dy) &
              lineMarkerSize,
          shapeType: ShapeMarkerType.diamond,
          paint: fillPaint,
        );
      }
    }
  }
}

Demo :

Image

Sample : GH_2287.zip

Regards,
Baranibharathi P.

@LavanyaGowtham2021 LavanyaGowtham2021 added waiting for customer response Cannot make further progress until the customer responds. and removed open Open labels Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
charts Charts component waiting for customer response Cannot make further progress until the customer responds.
Projects
None yet
Development

No branches or pull requests

4 participants