[Bug]: Not able to show selected y-value in the tooltip in a line chart
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.
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
-
Try following link: https://codepen.io/abhranilnaha/pen/raVPmer
-
Hover over any data point and it shows the first data point in the tooltip.
-
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.
-
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.
@Anush2303 Looks like we need to expose iscalloutforStack property for line chart also. Could you take a look.
@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 Dotted vertical line is by design. Could you log a separate issue for it
@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.
This issue has been fixed. Tracking PR #34757
@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 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 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:
Tooltip for non-anomalous data point:
@AtishayMsft Here is the example: https://codepen.io/abhranilnaha/pen/vEOMGLP
Please check the
onRenderCalloutPerStackcallback in the example where I used value ofprops.values[0].y. My expectation is that whenisCalloutForStack = true, I will receive aprops.yValuevalue of typeICustomizedCalloutDataPointin theonRenderCalloutPerStackcallback, 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 please merge the fix and provide me the new package version number. I will give it a try.
@abhranilnaha After the fix you will need to set isCalloutForStack = false and use onRenderCalloutPerDataPoint to get a single point value.
@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.
@AtishayMsft Is there any change in the
ICustomizedCalloutDatainterface inonRenderCalloutPerDataPointcallback for a single point value or does it look like this?export interface ICustomizedCalloutData { x: number | string | Date; values: ICustomizedCalloutDataPoint[]; }Here
valuesarray contains just one value.
@Anush2303 Can confirm on this.
@AtishayMsft Is there any change in the
ICustomizedCalloutDatainterface inonRenderCalloutPerDataPointcallback for a single point value or does it look like this?export interface ICustomizedCalloutData { x: number | string | Date; values: ICustomizedCalloutDataPoint[]; }Here
valuesarray contains just one value.@Anush2303 Can confirm on this.
Clarified this.
@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.
This is fixed in react-charting version 5.24.11