Hello,
The numbering here (below and in attached file, X axis) is not incorrect, but it is not good either. I would propose, you should use one more decimal place in this case. Could this be fixed from your side? I know I can use custom label format, but then I have to implement the whole logic, for all possible number combinations (you have this already implemented).
Thank you
Add decimal place
Moderator: Queue Moderators
-
- Posts: 141
- Joined: Wed Mar 27, 2019 1:05 pm
Re: Add decimal place
Hello,
I believe the easiest way to control the number of decimals is via LabelsNumberFormat. It affects all axis labels so it only has to be set once. It works if AutoFormatLabels is disabled.
_chart.ViewXY.XAxes[0].AutoFormatLabels = false;
_chart.ViewXY.XAxes[0].LabelsNumberFormat = "0.0"; // Always show one decimal
In this case just disabling AutoFormatLabels could be enough, since "0.0" is actually the default value of LabelsNumberFormat.
LabelsNumberFormat can be used to control the numbers before the decimals, in the following case shows 01.000, 10.000, 100.000 etc.
_chart.ViewXY.XAxes[0].LabelsNumberFormat = "00.000";
Best regards,
Lasse
I believe the easiest way to control the number of decimals is via LabelsNumberFormat. It affects all axis labels so it only has to be set once. It works if AutoFormatLabels is disabled.
_chart.ViewXY.XAxes[0].AutoFormatLabels = false;
_chart.ViewXY.XAxes[0].LabelsNumberFormat = "0.0"; // Always show one decimal
In this case just disabling AutoFormatLabels could be enough, since "0.0" is actually the default value of LabelsNumberFormat.
LabelsNumberFormat can be used to control the numbers before the decimals, in the following case shows 01.000, 10.000, 100.000 etc.
_chart.ViewXY.XAxes[0].LabelsNumberFormat = "00.000";
Best regards,
Lasse
Re: Add decimal place
Hello,
I understand that I can control the decimal places, but I really like that it is automatically rounded. If the numbers were 10times less, I would have the same problem with format "0.0". If the numbers were 100times less, it would show just zeros.
If there is no other way, I will have to implement label format for all possible values and all possible value ranges in FormatValueLabel, which is a huge job, which you already have done, but in my opinion you just have a small almost a bug there, when rounding.
In the picture, there is another problem, this time, not missing value, but 1 value twice. I understand where it comes from, here one more decimal point would again solve this. This one is done by providing majordiv an letting the graph decide where to put ticks. The one before was done using CustomTicks.
Is there something we can do?
Thank you
I understand that I can control the decimal places, but I really like that it is automatically rounded. If the numbers were 10times less, I would have the same problem with format "0.0". If the numbers were 100times less, it would show just zeros.
If there is no other way, I will have to implement label format for all possible values and all possible value ranges in FormatValueLabel, which is a huge job, which you already have done, but in my opinion you just have a small almost a bug there, when rounding.
In the picture, there is another problem, this time, not missing value, but 1 value twice. I understand where it comes from, here one more decimal point would again solve this. This one is done by providing majordiv an letting the graph decide where to put ticks. The one before was done using CustomTicks.
Is there something we can do?
Thank you
- Attachments
-
- Chart.PNG (15.02 KiB) Viewed 11213 times
-
- Posts: 141
- Joined: Wed Mar 27, 2019 1:05 pm
Re: Add decimal place
Hello,
You could check if FormatValueLabel -event works in your case. The logic inside this event is applied to each axis label. I don't think you need to apply logic for each value and range separately. Instead, you could for example count the number of decimals in the label and call Math.Round() based on that. For instance:
You can change the accuracy above by changing the decimals integer (i.e. decimals - 1).
Best regards,
Lasse
You could check if FormatValueLabel -event works in your case. The logic inside this event is applied to each axis label. I don't think you need to apply logic for each value and range separately. Instead, you could for example count the number of decimals in the label and call Math.Round() based on that. For instance:
Code: Select all
_chart.ViewXY.XAxes[0].AutoFormatLabels = false;
_chart.ViewXY.XAxes[0].FormatValueLabel += Example_FormatValueLabel;
private string Example_FormatValueLabel(object sender, FormatValueLabelEventArgs e)
{
int decimals = e.Value.ToString().Substring(e.Value.ToString().IndexOf(".") + 1).Length;
if (decimals > 15) // To prevent a possible OutOfRange exception.
decimals = 15;
return Math.Round(e.Value, decimals).ToString();
}
Best regards,
Lasse
Re: Add decimal place
Hello guys.
When I tried your proposal, here is my result. I cannot understand why is only each second label populated. Do you have some advice?
Thanks
When I tried your proposal, here is my result. I cannot understand why is only each second label populated. Do you have some advice?
Thanks
-
- Posts: 557
- Joined: Mon Mar 14, 2016 9:22 am
Re: Add decimal place
Hello,
Can you show all the settings for XAxis. This include property settings and event handlers.
I could image that label may disappear, if there is no space (too close to adjacent label). However, there is enough space in the image and that should happen only with CustomTick (normal tick removed together with label).
It could be Minor-ticks configured to be identical to Major-ticks, or completely different object (e.g. SeriesEventMarker).
After chart was rendered, you could ask array of ticks with
This should verify whatever those are major ticks.
Hope this helps.
Can you show all the settings for XAxis. This include property settings and event handlers.
I could image that label may disappear, if there is no space (too close to adjacent label). However, there is enough space in the image and that should happen only with CustomTick (normal tick removed together with label).
It could be Minor-ticks configured to be identical to Major-ticks, or completely different object (e.g. SeriesEventMarker).
After chart was rendered, you could ask array of ticks with
Code: Select all
axisX.GetMajorTicks()
Hope this helps.
Re: Add decimal place
I solved it with property AutoFormatLabels = false and LabelsNumberFormat = "0.00" and I think that I will be also able to solve with this way too big or too low numbers with exponent. I have one more question, am I somehow able to aling Ticks to start and end of Bar series (red arrows in picture)? Thanks for help guys
-
- Posts: 557
- Joined: Mon Mar 14, 2016 9:22 am
Re: Add decimal place
After chart is rendered, you can read size and position of each bar with
Code: Select all
System.Drawing.RectangleF[] aBarRect = chart.ViewXY.BarSeries[barIndex].GetBarRectangles();