Trying to Add a Top Axis

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Dave
Advanced
Posts: 139
Joined: Mon Sep 22, 2008 12:00 am

Trying to Add a Top Axis

Post by Dave » Mon Mar 29, 2021 5:30 pm

Hi

I create a simple line plot as shown below. Everything is great with the X and Y axis displayed and labelled correctly as expected.
However Id also like to display a top axis comprising integer values that match the number of items in the bottom X-axis.
So the top axis would be {1,2,3,4,5}. Is there an easy way to do this? Thanks.


Line plot = new Line();
plot.Title = "My Plot";

List<float> xAxis = new List<float>(5) { 9.3, 10.3, 11.3, 12.3, 13.3 };
List<float> yAxis = new List<float>(5) { 44, 19, 67, 87, 9 };

plot.Add(xAxis.ToArray(), yAxis.ToArray());
myChart.Series.Add(plot);

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Trying to Add a Top Axis

Post by Christopher » Tue Mar 30, 2021 2:55 pm

Hello Dave,

yes, possibly the easiest way to do this is to use Series labels, e.g.

Code: Select all

       private void InitializeTChart(TChart chart)
        {
            var plot = new Line
            {
                Title = "My Plot"
            };

            var xAxis = new List<float>(5) { 9.3f, 10.3f, 11.3f, 12.3f, 13.3f };
            var yAxis = new List<float>(5) { 44, 19, 67, 87, 9 };

            plot.Add(xAxis.ToArray(), yAxis.ToArray());
            chart.Series.Add(plot);


            var labels = new List<string>(5) { "1", "2", "3", "4", "5" };
            plot.HorizAxis = HorizontalAxis.Both;
            plot.Labels.AddRange(labels);
            chart.Axes.Top.Labels.Style = AxisLabelStyle.Text;
            chart.Axes.Bottom.Labels.Style = AxisLabelStyle.Value;
        }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Dave
Advanced
Posts: 139
Joined: Mon Sep 22, 2008 12:00 am

Re: Trying to Add a Top Axis

Post by Dave » Wed Mar 31, 2021 7:51 am

thanks!

Post Reply