Change Custom Y axis labels ONLY

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
asupriya
Advanced
Posts: 179
Joined: Mon Dec 01, 2008 12:00 am

Change Custom Y axis labels ONLY

Post by asupriya » Sun Nov 20, 2011 4:54 pm

I have a graph display with value vs. Time. The value gets changed with user options (such as display in Celsius or Fahrenheit) while the graph display remains same.

I need to change the min-max and other labels on axis without having to update all the series.Yvalues with the conversion factor when user selects different option. For example, if the initial display is in Celsius, when user selects Fahrenheit option, only the labels should change on the Y-axis without having to recompute all the Y-values. How can I do this?

Any help is greatly appreciated.

Thanks,

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Change Custom Y axis labels ONLY

Post by Narcís » Tue Nov 22, 2011 11:19 am

Hi asupriya,

You can manually customize labels in in the GetAxisLabel event as in the All Features\Welcome !\Axes\Labels\Using GetAxisLabel example at the features demo. You'll also find examples in tutorial 4, at the OnGetAxisLabel section. Both tutorials and features demo are available at TeeChart's program group.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Change Custom Y axis labels ONLY

Post by Sandra » Tue Nov 22, 2011 11:59 am

Hello asupriya,

To complete the information that Narcís suggested, I have made a simple example where I convert FahrenheitToCelsius and CelsiusToFahrenhe and change the labels, using custom labels, without modify the values of your series, please take a look in next example

Code: Select all

private void InitializeChart()
        {

            Steema.TeeChart.Styles.Line line1 = new Line(tChart1.Chart);
            tChart1.Aspect.View3D = false;
            Random rnd = new Random();
            checkBox1.Checked = true;
            checkBox1.CheckedChanged += new EventHandler(checkBox1_CheckedChanged);
            line1.Add(0, 200);
            line1.Add(1, 150);
            line1.Add(2, 45);
            line1.Add(3, 270);
            line1.Add(4, 100);
            line1.Add(5, 0);     
        }

        void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                tChart1.Axes.Left.Labels.Items.Clear();
                for (int i = 0; i < tChart1[0].Count; i++)
                {
                    tChart1.Axes.Left.Labels.Items.Add(tChart1[0].YValues[i], TemperatureConverter.CelsiusToFahrenheit(tChart1[0].YValues[i].ToString()).ToString());
                }
            }
            else
            {
                tChart1.Axes.Left.Labels.Items.Clear();
                for (int i = 0; i < tChart1[0].Count; i++)
                {
                    
                    tChart1.Axes.Left.Labels.Items.Add(tChart1[0].YValues[i], TemperatureConverter.FahrenheitToCelsius(tChart1[0].YValues[i].ToString()).ToString());
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            tChart1.ShowEditor();
            
        }
    }
    public static class TemperatureConverter
    {
        public static double CelsiusToFahrenheit(string temperatureCelsius)
        {
            // Convert argument to double for calculations.
            double celsius = System.Double.Parse(temperatureCelsius);

            // Convert Celsius to Fahrenheit.
            double fahrenheit = Math.Round((celsius * 9 / 5) + 32,2);

            return fahrenheit;
        }

        public static double FahrenheitToCelsius(string temperatureFahrenheit)
        {
            // Convert argument to double for calculations.
            double fahrenheit = System.Double.Parse(temperatureFahrenheit);

            // Convert Fahrenheit to Celsius.
            double celsius = Math.Round((fahrenheit - 32) * 5 / 9,2);

            return celsius;
        }
    }
}
Please can you tell us if previous code works as you expect?

I hope will help.
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Fenichel
Newbie
Newbie
Posts: 17
Joined: Fri Jul 19, 2024 12:00 am

Re: Change Custom Y axis labels ONLY

Post by Fenichel » Wed Aug 07, 2024 11:27 pm

Another approach to the Fahrenheit/Celsius problem (or mm Hg/PSI/pascals, etc) is to introduce one or more parallel axes. My utility to do the work for Fahrenheit/Celsius is on my Web site at https://www.fenichel.net/Celsius/CelsiusAxisDemo.zip. It requires that a new series be added to the chart, but the new series need not have any values or other parameters set, so the user can just stick it in at design time and forget it

One way of describing this approach is that I try to separate the notions of axes and scales.
  • Every series must be associated with an axis, because each axis defines minimum and maximum values, and the only plotted values, for any series associated with the axis, are those within the [minimum, maximum] bracket.
  • A scale shows ticks and calibrations, possibly connected to grid lines related to those calibrations. If there are multiple different units in which one might reckon the values of a series, a chart should be able to show as many scales as there are different units.

Post Reply