Add decimal place

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

MirroZV
Posts: 30
Joined: Wed May 13, 2020 10:41 am

Add decimal place

Post by MirroZV » Tue Oct 06, 2020 8:59 am

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).
chart.png
chart.png (13.45 KiB) Viewed 3499 times
Thank you

Arction_LasseP
Posts: 139
Joined: Wed Mar 27, 2019 1:05 pm

Re: Add decimal place

Post by Arction_LasseP » Wed Oct 07, 2020 8:07 am

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

MirroZV
Posts: 30
Joined: Wed May 13, 2020 10:41 am

Re: Add decimal place

Post by MirroZV » Thu Oct 08, 2020 7:06 am

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
Attachments
Chart.PNG
Chart.PNG (15.02 KiB) Viewed 3483 times

Arction_LasseP
Posts: 139
Joined: Wed Mar 27, 2019 1:05 pm

Re: Add decimal place

Post by Arction_LasseP » Thu Oct 08, 2020 9:36 am

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:

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();
}
You can change the accuracy above by changing the decimals integer (i.e. decimals - 1).

Best regards,
Lasse

MirroZV
Posts: 30
Joined: Wed May 13, 2020 10:41 am

Re: Add decimal place

Post by MirroZV » Fri Mar 12, 2021 12:24 pm

Hello guys.

When I tried your proposal, here is my result. I cannot understand why is only each second label populated.
result.PNG
result.PNG (13.67 KiB) Viewed 2781 times
Do you have some advice?

Thanks

ArctionKestutis
Posts: 445
Joined: Mon Mar 14, 2016 9:22 am

Re: Add decimal place

Post by ArctionKestutis » Fri Mar 12, 2021 2:11 pm

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

Code: Select all

axisX.GetMajorTicks()
This should verify whatever those are major ticks.

Hope this helps.

MirroZV
Posts: 30
Joined: Wed May 13, 2020 10:41 am

Re: Add decimal place

Post by MirroZV » Mon Mar 15, 2021 10:09 am

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 :)
Capture.PNG
Capture.PNG (20.62 KiB) Viewed 2767 times

ArctionKestutis
Posts: 445
Joined: Mon Mar 14, 2016 9:22 am

Re: Add decimal place

Post by ArctionKestutis » Tue Mar 16, 2021 9:45 am

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();