Forum Discussion
Dynamic y-Axis calculation with Deneb
- 1 year ago
Hi distra,
The area mark is designed to have a zero baseline, so even if you cut the domain, it is trying to plot the remainder of the shape outside the domain (as the second y-value is zero). It would work with a line mark as there is only a single y-coordinate to worry about.
So, what is happening here is that your y-scale and axis are being correctly set to the desired range, but the size of your chart is condensing the vertical scale into the equivalent amount of space. You can see it "kind of" working if you make the visual container larger, e.g.:
(ignore the 'undefined'; that's a copy/paste issue with your sample data at my end)
One way to resolve this is to instruct Vega-Lite to clip the area mark. You should be able to make the following changes to your spec:
1. Update the scale as follows (removing "zero": false), e.g.:
{ ... "encoding": { "y": { "field": "Avg Rate dynamic Currency", "type": "quantitative", "scale": { "domain": [80, 235] // or whatever you need min/max to be }, ... }, ... } ... }2. Update the area mark definition to include a clip as follows:
{ ... "layer": [ { "description": "sparkline definition", "mark": { "type":"area", "clip": true }, ... }, ... } ... }This will now cut the baseline of the plotted area, e.g.:
Hopefully this should be all you need to resolve. Good luck!
(and thanks for using Deneb!)
Daniel
Hello v-menakakota,
thank you for your reply. I checked the group and the two solved issues but unfortunately none of the displayed visuals contained what I need to achieve.
Maybe to make it clearer, all I need to achieve with this visual is to define a range for the y-axis which I want to see. Let me give you an example:
In my case I want the y axis to begin at the lower and at min_avg_rate - ( 40% of min_avg_rate). And the top end of the axis should be max_avg_rate + ( 40% of min_avg_rate).
And I tried to first scale the y-axis with static values, but even that gets me weird results. The boundaries are not respected and the y-Axis is not displayed properly anymore.
I am wondering if I defined the scale of the axis with the domain in the wrong place or in the wrong way.
Hi distra ,
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.
How to provide sample data in the Power BI Forum - Microsoft Fabric Community
Best Regards,
Community Support Team
- distra1 year agoFrequent Visitor
Hi v-menakakota,
please find the sample data in a usable format. Sorry for not providing it in this format earlier, I thought it was only needed to verify my defined y-Axis range is not too small for my actual range of values.
__row__ Month MonthName Avg Rate dynamic Currency Avg Rate formatted 0 2025-Jan
Jan
232,9179259 $ 232.92 1 2025-Feb
Feb
232,1264879 $ 232.13 2 2025-Mar
Mar
232,1775412 $ 232.18 3 2025-Apr
Apr
232,0739998 $ 232.07 4 2025-May
May
230,4090975 $ 230.41 5 2025-Jun
Jun
229,1148892 $ 229.11 6 2025-Jul
Jul
230,0921796 $ 230.09 7 2025-Aug
Aug
229,7630773 $ 229.76 8 2025-Sep
Sep
229,6737823 $ 229.67 9 2025-Oct
Oct
229,8118923 $ 229.81 10 2025-Nov
Nov
229,8118923 $ 229.81 11 2025-Dec
Dec
229,8935053 $ 229.89 Here is a quick summary on what I have vs. what I want to achieve:
I am very satisfied with the visual created, everything works well, besides the Y-Axis Range. By default it spans from 0 to a little above my maximum Value. As you can see in the table, my values for Avg Rate dynamic Currency are in a very small range, so the actual changes are hardly visible. So instead of the default range that should be about [0, 250], I want something like this:This was created using a standard Line chart in Power BI. But I would prefer to use my custom Deneb visual over this one, because when I hover I immediately see the current month's value in the proper format, without needing a tooltip.
I hope this is clearer, all that's missing is the ability to set the axis on my Deneb chart to a smaller range. For the reference chart with the standard line chart I used the exact same data with a y-Axis range of [225, 235].
- v-menakakota1 year agoCommunity Support
Hi distra ,
Apologies for the delayed response. Could you please review the following configuration and confirm if it meets the requirement."scale": {
"zero": false,
"domain": [225, 235]
}
If I misunderstand your needs or you still have problems on it, please feel free to let us know.
Best Regards,
Community Support Team- distra1 year agoFrequent Visitor
Hello v-menakakota,
no problem at all, take all the time you need please.
It was my understanding that the exact code you put there would scale my y-Axis to the samE range that I had shared in my example. However, when I add it, the visual output is the following:
The y-Axis and area shading completely disappear, although the range is absolutely correct.
For your reference, I added it here:
"encoding": { "y": { "field": "Avg Rate dynamic Currency", "type": "quantitative", "scale": { "zero": false, "domain": [225, 235] }, "axis": { "title": null, "labels": true, "ticks": true, "grid": true, "domain": true, "labelColor": "#605E5C", "labelFont": "Segoe UI Semibold", "labelFontSize": 10, "tickColor": "#E1DFDD", "gridColor": "#F3F2F1", "domainColor": "#E1DFDD" } }, "x": { "field": "Month", "type": "temporal" } },This is the encoding block after the fransforms and before the layers (please reference my full configuration in my other comment if more context is needed). If I defined it in the wrong way or position, please let me know. I am quite confused why this does not work, because I had exactly the same approach.
Thank you for your continous support!