fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

[Bug]: Not able to show selected y-value in the tooltip in a line chart

Open abhranilnaha opened this issue 1 year ago • 16 comments

Charting Control

LineChart

Package version

5.23.92

React version

19.0.0

Environment

https://codepen.io/abhranilnaha/pen/raVPmer

Current Behavior

When user hovers over a data point in a line chart, it shows all the data points for the vertical line, instead of showing showing the data point on which user hovered.

Image

Expected Behavior

We should have capability to get the y-value for the selected data point in the line chart.

Reproduction

https://codepen.io/abhranilnaha/pen/raVPmer

Steps to reproduce

  1. Try following link: https://codepen.io/abhranilnaha/pen/raVPmer

  2. Hover over any data point and it shows the first data point in the tooltip.

Image

  1. onRenderCalloutPerDataPoint for Line Chart contains the following props: x is the selected x-value and values contain all data point values for the vertical line.

  2. Need capability to get the y-value of the data point on which user hovered.

export interface ICustomizedCalloutData {
    x: number | string | Date;
    values: ICustomizedCalloutDataPoint[];
}
 
export interface ICustomizedCalloutDataPoint {
    legend: string;
    y: number;
    color: string;
    xAxisCalloutData?: string;
    yAxisCalloutData?: string | {
        [id: string]: number;
    };
}

Are you reporting an Accessibility issue?

None

Suggested severity

Urgent - No workaround and Products/sites are affected

Products/sites affected

Fabric Real Time Intelligence

Are you willing to submit a PR to fix?

yes

Validations

  • [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • [x] The provided reproduction is a minimal reproducible example of the bug.

abhranilnaha avatar Jun 26 '25 05:06 abhranilnaha

@Anush2303 Looks like we need to expose iscalloutforStack property for line chart also. Could you take a look.

AtishayMsft avatar Jun 27 '25 08:06 AtishayMsft

@Anush2303 Please also check if there is a way to hide the dotted vertical line. When we show a single data point in the tooltip when user hovers over it, we should not show the dotted vertical line.

abhranilnaha avatar Jun 27 '25 21:06 abhranilnaha

@abhranilnaha Dotted vertical line is by design. Could you log a separate issue for it

AtishayMsft avatar Jun 28 '25 00:06 AtishayMsft

@Anush2303 / @AtishayMsft, do you have an ETA for this fix? We have our Private Preview on July 14th and it will be great if we can get this fix in this week to incorporate it in our private preview.

abhranilnaha avatar Jun 30 '25 16:06 abhranilnaha

This issue has been fixed. Tracking PR #34757

AtishayMsft avatar Jul 01 '25 01:07 AtishayMsft

@Anush2303 I plan to utilize the onRenderCalloutPerDataPoint or onRenderCalloutPerStack callback here to customize the tooltip like below using ChartHoverCard:

** onRenderCalloutPerStack={(props: ICustomizedCalloutData) => props ? ( <ChartHoverCard XValue={String(props.x)} Legend={groupLabel} YValue={props.y} color={isAnomalous ? 'red' : 'green'} descriptionMessage={Is anomalous?: ${isAnomalous}} /> ) : null }**

As you can see, I am showing the legend in red color when the data point is anomalous and in green when it is not. Please make sure, the above fix supports this use case.

abhranilnaha avatar Jul 01 '25 02:07 abhranilnaha

@abhranilnaha Could you share your complete code changes as a code pen repro. Or take the current PR fix and verify at your end. The code pointer shared above is incomplete and not verifiable.

AtishayMsft avatar Jul 01 '25 02:07 AtishayMsft

@AtishayMsft Here is the example: https://codepen.io/abhranilnaha/pen/MYwRqoW

Please check the onRenderCalloutPerStack callback in the example where I used value of props.values[0].y. My expectation is that when isCalloutForStack = true, I will receive a props.yValue value of type ICustomizedCalloutDataPoint in the onRenderCalloutPerStack callback, which I can use to render the ChartHoverCard with the following:

onRenderCalloutPerStack={(props: ICustomizedCalloutData) =>
    props ? (
      <ChartHoverCard
           XValue={new Date(props.x).toLocaleString()}
           Legend={props.yValue..yAxisCalloutData}
           YValue={props.yValue.y}
           color={props.yValue.y > 250000 ? 'red' : 'green'}
           descriptionMessage={`Is anomalous?: ${props.yValue.y > 260000}`}
       />
   ) : null
}

Tooltip for anomalous data point: Image

Tooltip for non-anomalous data point: Image

abhranilnaha avatar Jul 01 '25 05:07 abhranilnaha

@AtishayMsft Here is the example: https://codepen.io/abhranilnaha/pen/vEOMGLP

Please check the onRenderCalloutPerStack callback in the example where I used value of props.values[0].y. My expectation is that when isCalloutForStack = true, I will receive a props.yValue value of type ICustomizedCalloutDataPoint in the onRenderCalloutPerStack callback, which I can use to render the ChartHoverCard with the following:

onRenderCalloutPerStack={(props: ICustomizedCalloutData) => props ? ( <ChartHoverCard XValue={new Date(props.x).toLocaleString()} Legend={props.yValue..yAxisCalloutData} YValue={props.yValue.y} color={props.yValue.y > 250000 ? 'red' : 'green'} descriptionMessage={Is anomalous?: ${props.yValue.y > 260000}} /> ) : null }

Pls take the fix. It will work as per your expectation

Anush2303 avatar Jul 01 '25 06:07 Anush2303

@Anush2303 please merge the fix and provide me the new package version number. I will give it a try.

abhranilnaha avatar Jul 01 '25 06:07 abhranilnaha

@abhranilnaha After the fix you will need to set isCalloutForStack = false and use onRenderCalloutPerDataPoint to get a single point value.

AtishayMsft avatar Jul 01 '25 06:07 AtishayMsft

@AtishayMsft Is there any change in the ICustomizedCalloutData interface in onRenderCalloutPerDataPoint callback for a single point value or does it look like this?

export interface ICustomizedCalloutData {
    x: number | string | Date;
    values: ICustomizedCalloutDataPoint[];
}

Here values array contains just one value.

abhranilnaha avatar Jul 01 '25 09:07 abhranilnaha

@AtishayMsft Is there any change in the ICustomizedCalloutData interface in onRenderCalloutPerDataPoint callback for a single point value or does it look like this?

export interface ICustomizedCalloutData {
    x: number | string | Date;
    values: ICustomizedCalloutDataPoint[];
}

Here values array contains just one value.

@Anush2303 Can confirm on this.

AtishayMsft avatar Jul 01 '25 10:07 AtishayMsft

@AtishayMsft Is there any change in the ICustomizedCalloutData interface in onRenderCalloutPerDataPoint callback for a single point value or does it look like this?

export interface ICustomizedCalloutData {
    x: number | string | Date;
    values: ICustomizedCalloutDataPoint[];
}

Here values array contains just one value.

@Anush2303 Can confirm on this.

Clarified this.

Anush2303 avatar Jul 01 '25 10:07 Anush2303

@Anush2303 It is not working It is returning an array of values in onRenderCalloutPerDataPoint callback when isCalloutForStack=false. It is supposed to return only 1 item in the values array.

Image

abhranilnaha avatar Jul 02 '25 08:07 abhranilnaha

This is fixed in react-charting version 5.24.11

AtishayMsft avatar Jul 04 '25 01:07 AtishayMsft