Some bars in bar chart miss figures
Closed this issue ยท 10 comments
I used ver 1.8.0 in Windows Forms application in .Net 7. "YValueMembers" are not shown properly. I am showing shipments of 12 months using bar chart and highest value is 426 but the max Y value shown is 200. So, those bars are missing figures on top of them that are more than 200 (see the attached image). Figures for last three months are Apr = 426, May = 231, Jun = 266. The chart was working fine in .Net Framework application. Max value shown on Y-side should be max value of chart data + 20% so that figures on top of bars are shown properly. I am using Visual Studio 2022 ver 17.7.4
Hello @sirfana. Unfortunately it's not possible to determinate problem with such common description. You need to provide more details with code and data. Ideally a repro project.
The issue was little different that popped up after detailed investigation. Values shown on Y axis were not recalculated when charts were viewed for different data sets. Values on Y axis shown for the first chart were retained for the subsequent charts that caused missing of few figures on top of bars. Adding the following statement has fixed the issue:
chart1.ResetAutoValues();
After the above statement, values on Y axis are recalculated when charts are viewed for different data sets.
I am glad you can solve your problem. If you provide some sample, I can try to investigate different behaviour between .net framework and .Net.
Hello @kirsan31, see the attached VS solution. It's a Windows Forms application in .Net 6 (VS 2022 ver 17.7.4) + your NuGet package of WinForms.DataVisualization. Run it and see figures for year 2023. Then change year to 2022 and note than values on Y axis are not recalculated for new data set. This was what i coded in my previous app in Visual Studio 2019 + .Net Framework 4.6.1 and the charts provided in VS. Values on Y axis were automatically recalculated. In your version of the control, values on Y axis are not automatically recalculated. Uncomment the following statement in three methods (in Form1.cs) and then values are auto recalculated:
chartXYZ.ResetAutoValues();
You can download the VS solution from below link:
https://drive.google.com/file/d/1E4wWxQk8sAPrHdfJ3FzTTedhnxzlfIFa/view?usp=sharing
Thank you, I will check it as soon as have some free time...
P.s. you can attach files direct to messages here at github.
@sirfana I think I Found where the problem is... This is a side effect of breaking change of 1.8 release:
Small breaking change.
If you use Axes auto min \ max values and call
DataPointCollection.Clear()
method for already empty collection:
- Old behavior - axes min \ max values will be recalculated on next chart paint.
- New behavior - axes min \ max values will not be recalculated.
If you try 1.7 - all will work without ResetAutoValues
. This is very strange, I'll see what I can do about it...
I think maintaining the old behavior is preferred but (since behavior is now changed in 1.8), it is tricky what to do. BTW, what was the reason of adopting "New Behavior"?
The whole point is that this change should not have led to any internal consequences. ๐ค Still investigating...
BTW, what was the reason of adopting "New Behavior"?
If collection already empty when you call clear - for what to do anything?
Then the question is what caused change in behavior? My problem is solved with the addition of a statement but you should stick to "Old behavior" in newer version since that's the safest approach to keep things working as they were in .Net Framework. For those who are porting applications from .Net Framework to .Net 6 and above and using your control, for them it will be very hard and tricky to know the "New Behavior". Thinks will perform unexpectedly.
Yes, databinding is using this - recalculate axes after clearing of empty collection :( I think I will revert to old behavior...
P.s. more proper way to recalculate axes is call chartSaleSummary.ChartAreas[0].RecalculateAxesScale();
after binding.
P.p.s. I also found a bug in 1.9 with your sample... You need to set IsXValueIndexed = true
for all series to get it work in 1.9.