Value formatting of the scale label depending on the value.


Author
Message
Fabio Olcese
Fabio Olcese
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)
Group: Forum Members
Posts: 11, Visits: 40
Hi,

I was wondering if there was a way to format values depending on the value itself. For example in a NumerixAxis using a NLinearScaleConfigurator, if the label is a number greater or equal 1 000 000 use scientific notation otherwise just display the number.

Thanks in advance!
Tags
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.1K
Hi Fabio,
Yes it is possible to have formatting dependent on the value - the following code shows how to create a custom value formatter which formats values greater than 1000 to 1K, 2K etc:

        class CustomValueFormatter : NValueFormatter
        {
            public override string FormatValue(double value)
            {
                if (value >= 1000)
                {
                    return ((int)value / 1000).ToString() + "K";
                }

                return value.ToString();
            }

            public override string FormatValue(object value)
            {
                return FormatValue((double)value);
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            NChart chart = nChartControl1.Charts[0];

            NBarSeries bar = new NBarSeries();

            bar.Values.Add(10);
            bar.Values.Add(100);
            bar.Values.Add(1000);

            chart.Series.Add(bar);

            NLinearScaleConfigurator linearScale = chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator as NLinearScaleConfigurator;

            linearScale.LabelValueFormatter = new CustomValueFormatter();
        }

Hope this helps - let us know if you meet any problems or have any questions.


Best Regards,
Nevron Support Team


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic
3 active, 3 guests, 0 members, 0 anonymous
No members currently viewing this topic!

Login

Explore
Messages
Mentions
Search