Page 1 of 1

labels ammount

Posted: Sun Jun 28, 2009 11:56 am
by 13051139
Hi
I need to control how much labels I want to show.
I have an X axis (DateTime) and I need to show grid lines every week.
How can I do this?

Thanks a lot

Re: labels ammount

Posted: Mon Jun 29, 2009 9:04 am
by 10050769
Hello Igor G,

I make a simple example that you can use similar code for your application,think solve your problem using property of Bottom.Increment and Steema.TeeChart.Utils.GetDateTimeSteps(Steema.TeeChart.DateTimeSteps.OneWeek). Also you can use more type DateTimeSteps for increment axes labels for example: oneday, twodays, onemonth etc. DateTimeSteps as you see is using when you would increment DateTime for differents days,month,years etc.

Code: Select all

     private Steema.TeeChart.Styles.Line line1;
        private void InitializeChart()
        {
            line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            line1.FillSampleValues();
            line1.XValues.DateTime = true;
            tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/MM/yyyy";
            tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneWeek);
        }
I hope that will helps

Thanks,

Re: labels ammount

Posted: Mon Jun 29, 2009 9:12 am
by 13051139
Hi
This is not so good - this will decrease a total ammount of labels.
I will describe my situation:
I have a graph with 720 x values (increment is 2 hours).
I want to stay at 2 hours resolution but when I display this graph I just want the grid lines to be drawn every week.
Thats all:)
Thanks

Re: labels ammount

Posted: Tue Jun 30, 2009 9:17 am
by 10050769
Hello Igor G,

I make a simple example, that I think solve your problem. Please check next code works fine.

Code: Select all

  private Steema.TeeChart.Styles.Line line1;
        private void InitializeChart()
        {
          
            line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            tChart1.Dock = DockStyle.Fill;

            Random y = new Random();

            for (int i = 0; i < 720; i++)
            {
                line1.Add(DateTime.Now.AddHours(i*2), y.Next());
            }
            line1.XValues.DateTime = true;
            tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/MM/yyyy hh:mm";
            tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.TwoHours);
            tChart1.Axes.Bottom.Labels.Angle = 90;
            tChart1.Axes.Left.Grid.Visible = false;
            tChart1.Axes.Bottom.Grid.Visible = false;

            tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
        }

        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            int tmp = (int)Math.Ceiling(line1.XValues[0]);

            for (int i = tmp; i < line1.MaxXValue(); i=i+7)
            {
                int tmpX = tChart1.Axes.Bottom.CalcPosValue(i);
                Rectangle rect = tChart1.Chart.ChartRect;

                g.Pen.Color = Color.Red;
                g.Pen.Style = System.Drawing.Drawing2D.DashStyle.Dash;
                g.Line(tmpX, rect.Bottom, tmpX, rect.Top);        
            }
        }
I hope that will helps.


Thanks,