Profile Picture

Value formatting of the scale label depending on the value.

Posted By Fabio Olcese 8 Years Ago

Value formatting of the scale label depending on the value.

Author
Message
Fabio Olcese
Question Posted 8 Years Ago
View Quick Profile
Forum Newbie

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
Last Active: 8 Years Ago
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
Posted 8 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,018
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





Similar Topics


Reading This Topic