Page 1 of 1

Use IFormatProvider to format axis labels

Posted: Fri Sep 16, 2011 7:20 am
by 13049569
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

Re: Use IFormatProvider to format axis labels

Posted: Fri Sep 16, 2011 2:33 pm
by 10050769
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,

Re: Use IFormatProvider to format axis labels

Posted: Mon Sep 19, 2011 9:46 am
by 13049569
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

Re: Use IFormatProvider to format axis labels

Posted: Mon Sep 19, 2011 12:21 pm
by 10050769
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,