How to Place Chart Annotation Above Highest Series (Column or Line) for Each X Value in Multi-Series Syncfusion Blazor Chart?
I’m using a Syncfusion Blazor chart with both a column series and a line series, with the X axis as dates. For each date, I want to display an annotation label above the highest value—whether that’s the bar or the line.
Context:
- Sometimes the column is higher, sometimes the line is higher.
- The annotation should always sit above the highest point for that date, never overlapping the bar or the line.
- The annotation should never overflow outside the chart’s Y axis bounds.
Current Issue:
- With `CoordinateUnits="Units.Point"` and the annotation Y set to the line value, it overlaps the bar when the bar is higher (and vice versa).
- As for overflow issue, the workaround I’ve found is to pad the Y axis maximums, but that does not feel elegant
- I don’t know how to programmatically place the annotation above the higher of the two series for each X value, without manually mapping between axes or using trial-and-error padding.
- As you can see below, for 11/11/2025, the label overlaps the bar which I don't want.
Question:
- What is the best, most robust way to always place an annotation above the highest value (bar or line) for each X value, without overlap and without the annotation overflowing the chart area?
- Is there a built-in way to get the maximum Y value for all series at a given X, or a recommended pattern for this scenario?
- Is there a way to ensure the annotation always fits within the Y axis bounds?
Minimal Repro (Syncfusion Blazor Playground):
https://blazorplayground.syncfusion.com/rtByMMsjwSLwIWeo
Thank You.
Repro code (for future reference):
Hi Ashish,
Thank you for reaching out.
We have analyzed your required scenario. Since column and line series uses different Y axes(Y1 and Y2) with different numeric ranges, so you need to normalize them to common coordinate system. We suggest you to convert both y values into the percentage of their respective axis range. Then this value can be used to determine which one is visually higher, and annotation can be placed slightly above the higher one.
We have attached the modified sample for your reference.
|
<ChartAnnotations> @foreach (var point in Data) { var barPercent = (point.BarValue - 12000) / (ValueYAxisMaximum - 12000); var linePercent = (point.LineValue - 0) / (TempYAxisMaximum - 0);
bool isBarHigher = barPercent >= linePercent;
// Convert back to actual Y value on the correct axis for annotation placement var yAxis = isBarHigher ? "Y1" : "Y2"; double baseValue = isBarHigher ? point.BarValue : point.LineValue; double paddingFactor = isBarHigher ? 0.03 : 0.15; // Adjust separately for clarity double yValue = baseValue * (1 + paddingFactor);
<ChartAnnotation CoordinateUnits="Units.Point" X="@point.Date" Y="@yValue.ToString("0.##")" YAxisName="@yAxis"> <ContentTemplate> <div style="background:#fff; border:1px solid #333; border-radius:4px; padding:2px 8px; font-size:13px;"> @($"Above {(isBarHigher ? "Bar" : "Line")}") </div> </ContentTemplate> </ChartAnnotation> } </ChartAnnotations> |
Sample : https://blazorplayground.syncfusion.com/VjrIWMCiyjBdKXKa
By default, when range is not specified, the axis interval will be calculated based on specified data points. To increase the additional range, you can specify RangePadding as Additional for Y axis.
Please let us know if you have any concerns.
Regards,
Durga Gopalakrishnan.
Hi Durga,
Thanks for your help and suggestions.
I’ve found it quite difficult to adjust the Y1/Y2 axes manually.
- If I set the axis maximums a bit high, it leaves a large empty space at the top of the chart, making it look unbalanced.
- Using `RangePadding="ChartRangePadding.Additional"` didn’t work well for me either—the annotations still didn’t get placed smartly, and the chart often looked awkward.
As you suggested, I’m currently using a percent-of-axis approach to decide which series is visually higher for annotation placement. However, because the Value (Y1) axis range is much larger than the Temp (Y2) axis, this method tends to favor the bar, even when the line is visually higher on the chart.
Notice for Wed, 11/12/2025, the label should have been placed above line chart, but it gets placed under it.
To compensate, I subtract 10% from the bar’s percent as a heuristic, but this is not mathematically robust and may not work for all data/range scenarios.
The only good enough solution I have so far is:
- Pad both Y axes maximums by 15% (for annotation space).
- Capture the actual plotted Y axis minimums and maximums using the `OnAxisActualRangeCalculated` event.
- Use these plotted min/max values for the percent calculation for annotation placement. Also, substract 10% from barPercent to avoid above mentioned issue.
https://blazorplayground.syncfusion.com/VjVeMMsVcBpPolMC
Is there a better way to have the chart auto-adjust the axes based on annotation placement, so I don’t have to manually pad the axis maximums or rely on this kind of heuristic? Or is this the best approach for now?
Here’s the relevant code:
Thanks again for your help!
Ashish,
Most welcome. We would like to clarify the behavior of axis range. By default, when an axis range is not explicitly provided, it is automatically calculated based on the available data points. When range is specified for axis, then the calculated range remains static even while updating data or any other dynamic process.
Unfortunately, we do not currently support automatically increasing the axis range based on annotation values.
For scenarios where annotations overlap or extend beyond the specified axis range, we recommend you to manually increase the axis range to ensure the annotations are fully visible without overlap.
Please let us know if you have any questions or concerns.
- 4 Replies
- 2 Participants
-
AK Ashish Khanal
- Nov 10, 2025 09:16 PM UTC
- Nov 13, 2025 12:38 PM UTC