Page 1 of 1

Trying to Add a Top Axis

Posted: Mon Mar 29, 2021 5:30 pm
by 13050364
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);

Re: Trying to Add a Top Axis

Posted: Tue Mar 30, 2021 2:55 pm
by Christopher
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;
        }

Re: Trying to Add a Top Axis

Posted: Wed Mar 31, 2021 7:51 am
by 13050364
thanks!