Page 1 of 1

Create separate bottom axis for hours format and date format at a time.

Posted: Thu Mar 19, 2020 2:15 pm
by 9641422
Hi Steema,

We have use TChart.Net 2012. We have XY data in which X values are in date time format. We have created a line series to plot this data in the charts. Now our requirements is that we want to display the hours in primary axis( in 24 hours format) in the bottom and date is displaying in secondary axis in the bottom of the chart. This hours labels created on the bases of date time data.
For your reference we have attached a image.
So kindly provide the solution for same.

Thanks
Amol

Re: Create separate bottom axis for hours format and date format at a time.

Posted: Mon Mar 23, 2020 10:00 am
by Christopher
Hello Amol,

you could base your solution on code similar to this:

Code: Select all

        private void InitializeChart()
        {
            var line = new Line(_tChart.Chart);

            var now = DateTime.UtcNow;
            var rnd = new Random();

            for (var i = 0; i < 50; i++)
            {
                line.Add(now, rnd.Next(1000));
                now = now.AddHours(4);
            }

            _tChart.Axes.Bottom.Increment = (1 / 24) * 4;
            _tChart.Axes.Bottom.Labels.DateTimeFormat = "HH";
            _tChart.Axes.Bottom.Grid.Visible = false;

            var axis = _tChart.Axes.Bottom.SubAxes.Add();
            axis.Increment = 1;
            axis.Labels.DateTimeFormat = "M";
            axis.GetAxisDrawLabel += Bottom_GetAxisDrawLabel;
            axis.Grid.DrawEvery = 1;
            axis.Grid.Color = Color.Red;
        }

        private void Bottom_GetAxisDrawLabel(object sender, GetAxisDrawLabelEventArgs e)
        {
            var axis = sender as Axis;
            var size = axis.CalcSizeValue(1);
            e.X += size / 2;
        }
Which here gives me:
TeeChartPro_2020-03-23_10-58-35.png
TeeChartPro_2020-03-23_10-58-35.png (59.9 KiB) Viewed 19902 times

Re: Create separate bottom axis for hours format and date format at a time.

Posted: Sat Mar 28, 2020 9:41 am
by 9641422
Hi Steema,

Thanks for the reply. We have used your code as you mentioned in your demo but i have not able to use "SubAxes" for bottom axis. The code as you mentioned in below:

var axis = _tchart.Axes.Bottom.SubAxes.Add();

Here we are using TChart Dot Net version 2012.

So kindly guide us how we use "SubAxes" for bottom.

Thanks & regards
Amol

Re: Create separate bottom axis for hours format and date format at a time.

Posted: Mon Mar 30, 2020 6:23 am
by Christopher
Hello Amol,

you can see the code working by downloading the NuGet package from here; you can either use Visual Studio to install the package or you can download it and unzip it to access the TeeChart assemblies.

The SubAxes feature may not be a feature available in TeeChart 2012, but I am not authorized to effectively give you the source code for this new feature.