Use IFormatProvider to format axis labels

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
BMS
Newbie
Newbie
Posts: 2
Joined: Wed Jul 09, 2008 12:00 am

Use IFormatProvider to format axis labels

Post by BMS » Fri Sep 16, 2011 7:20 am

Hello,

On the vertical axis, I'm plotting a timespan (expressed in minutes). I've got a class that implements IFormatProvider/ICustomFormatter to convert a number of minutes (and fractional seconds) into a more readable [d ][hh:]mm:ss notation (that I'm using in the grid version of my report).

Is there any way to use this to format the axis labels? I've tried the chart.GetAxisLabel (but the e.Series is always NULL) and axis.GetAxisDrawLabel (but that event is also raised to draw the axis title).

I was hoping to find a Axis.Right.Labels.Format property of type IFormatProvider that I could use, but I only found format strings.

I'm using TeeChart 3.5.3498.27368.

Thanks

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

Re: Use IFormatProvider to format axis labels

Post by Sandra » Fri Sep 16, 2011 2:33 pm

Hello BMS,

You need change format of DateTimeformat property of Axes labels. I think you can do something as next:

Code: Select all

  private void InitializeChart()
        {
            Steema.TeeChart.Styles.Line line1 = new Line(tChart1.Chart);
            line1.FillSampleValues();
            line1.XValues.DateTime = true;
            tChart1.Axes.Bottom.Labels.DateTimeFormat = "[d][hh:]mm:ss"; 
          }
Can you tell us, if previous code woks as you want?

I hope will helps.

Thanks,
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

BMS
Newbie
Newbie
Posts: 2
Joined: Wed Jul 09, 2008 12:00 am

Re: Use IFormatProvider to format axis labels

Post by BMS » Mon Sep 19, 2011 9:46 am

Hello,

Thanks for the reply. Unfortunately, your solution doesn't work for me, as it seems to need a DateTime value and not a TimeSpan (which is what I've got).

The table below shows the data I want to show in the chart:

Code: Select all

Stop Description   Number of Stops     StopTime
---------------------------------------------------
1. Hand Stop       15                  19.5 (19:30)
24. No Fill        8                   61.25 (1:01:15)
The Stop Descriptions are the labels for the bottom axis. The left axis shows the number of stops, the right axis shows the stop time.

Here's what I get (with the timespan between parentheses being what I want to achieve):

Code: Select all

  20 -|                                |- 80 (1:20:00)
  15 -|     X                  Y       |- 60 (1:00:00)
  10 -|     X                  Y       |- 40   (40:00)
   5 -|     X               X  Y       |- 20   (20:00)
   0 -|_____X__Y____________X__Y_______|- 0     (0:00)
      1. Hand Stop     24. No Fill
I'm feeding the chart values as follows:

Code: Select all

private void addChartData()
{
  seriesStopNumber.Add(15, "1. Hand Stop");
  seriesStopNumber.Add(8, "24. No Fill");

  seriesStopTime.Add(19.5, "1. Hand Stop");
  seriesStopTime.Add(61.25, "24. No Fill");
}
For small numbers this may seem unnecessary, but 14:39:13 is easier to use than 879.2167 minutes.

Best regards

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

Re: Use IFormatProvider to format axis labels

Post by Sandra » Mon Sep 19, 2011 12:21 pm

Hello BMs,

Ok, I have made a simple code that works with DateTime, where I have added minutes and I think can help you to solve your problem:

Code: Select all

   public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        System.DateTime DateTime1;
        Steema.TeeChart.Styles.Points points1,points2;
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            points1 = new Points(tChart1.Chart);
            points1.Add(15);
            points1.Add(8);
            points1.Add(7);
            points1.Add(10);

            //Add DateTimePoints. 
            points2 = new Points(tChart1.Chart);
            DateTime1 = new DateTime();
            points2.YValues.DateTime = true;
            points2.VertAxis = VerticalAxis.Right;
            points2.DateTimeFormat = "HH:mm:ss";
            points2.Add(0,DateTime1.AddMinutes(19.5).ToOADate());
            points2.Add(1, DateTime1.AddMinutes(61.25).ToOADate());
            points2.Add(2, DateTime1.AddMinutes(80.75).ToOADate());
            points2.Add(3, DateTime1.AddMinutes(122.50).ToOADate());
            tChart1.Axes.Right.Labels.DateTimeFormat = "HH:mm:ss";
         
        }
Can you confirm us, if previous code works as you expected?

I hope will helps.

Thanks,

Post Reply