Page 1 of 1

Change Custom Y axis labels ONLY

Posted: Sun Nov 20, 2011 4:54 pm
by 13051032
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,

Re: Change Custom Y axis labels ONLY

Posted: Tue Nov 22, 2011 11:19 am
by narcis
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.

Re: Change Custom Y axis labels ONLY

Posted: Tue Nov 22, 2011 11:59 am
by 10050769
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.

Re: Change Custom Y axis labels ONLY

Posted: Wed Aug 07, 2024 11:27 pm
by 17598411
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.