Grid in Rectangle tool

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Amol
Advanced
Posts: 176
Joined: Mon May 29, 2006 12:00 am

Grid in Rectangle tool

Post by Amol » Thu May 15, 2014 2:12 pm

Hi Steema Support,
Many thanks for your reply and given examples but it is not same thing for what we are looking.
We cannot drag Rectangle Tool smoothly if we drag through Datagridview and show flickering. And when we export picture of teechart then it does not export Datagridview (Only show Rectangle Tool)


It will be very helpful for us, if you please provide any alternative solution as soon as possible.

Thanks in advance.


Thanks and Regards
Planoresearch

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Grid in Rectangle tool

Post by Christopher » Fri May 16, 2014 9:42 am

Hello!

The only other solution I can think of is you manually draw your own grid within a custom RectangleTool, e.g.

Code: Select all

 public class MyRectangleTool : RectangleTool
  {
    public MyRectangleTool()
      : this((Chart)null)
    {
    }

    public MyRectangleTool(Chart c)
      : base(c)
    {
    }

    protected override void ChartEvent(EventArgs e)
    {
      base.ChartEvent(e);
      if (e is AfterDrawEventArgs)
      {
        DrawGrid(Chart.Graphics3D, Bounds);
      }
    }

    const double numCols = 3.0;
    const double numRows = 3.0;

    private void DrawGrid(Graphics3D g, Rectangle rect)
    {
      int horizIncrement = Utils.Round((double)rect.Width / numCols);
      int vertIncrement = Utils.Round((double)rect.Height / numRows);

      for (int i = rect.Left; i < rect.Right; i += horizIncrement)
      {
        g.VerticalLine(i, rect.Top, rect.Bottom - 1);
      }

      for (int i = rect.Top; i < rect.Bottom; i += vertIncrement)
      {
        g.HorizontalLine(rect.Left, rect.Right - 1, i);
      }
    }
  }
again, using it like this:

Code: Select all

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      Line line = new Line(tChart1.Chart);
      line.FillSampleValues();

      MyRectangleTool tool = new MyRectangleTool(tChart1.Chart);
      tool.Shape.Transparency = 0;
      tool.Width = 100;
      tool.Left = 100;
      tool.Top = 100;
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Amol
Advanced
Posts: 176
Joined: Mon May 29, 2006 12:00 am

Re: Grid in Rectangle tool

Post by Amol » Mon Nov 24, 2014 1:23 pm

Hi Steema Support,

Can you write data in each row? We are using this g.TextOut(i, rect.Top, rect.Bottom - 1, "HI"); to write but this method write only one row not all. Image is attached

for (int i = rect.Left; i < rect.Right; i += horizIncrement)
{
g.VerticalLine(i, rect.Top, rect.Bottom - 1);

g.TextOut(i, rect.Top, rect.Bottom - 1, "HI");
}
img.png
Image
img.png (107.66 KiB) Viewed 10894 times
Thanks in advance.

Thanks & Regards
PlanoResearch

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Grid in Rectangle tool

Post by Christopher » Tue Nov 25, 2014 9:59 am

Amol wrote:Can you write data in each row?
This is a basic programming task which is not TeeChart API specific. You could do something like this:

Code: Select all

    protected override void ChartEvent(EventArgs e)
    {
      base.ChartEvent(e);
      if (e is AfterDrawEventArgs)
      {
        DrawGrid(Chart.Graphics3D, Bounds);
        DrawCells(Chart.Graphics3D, Bounds);
      }
    }


    private void DrawCells(Graphics3D g, Rectangle rect)
    {
      int horizIncrement = Utils.Round((double)rect.Width / numCols);
      int vertIncrement = Utils.Round((double)rect.Height / numRows);

      for (int i = rect.Left; i < rect.Right - 1; i += horizIncrement)
      {
        for (int j = rect.Top; j < rect.Bottom; j += vertIncrement)
        {
          g.TextOut(i, j, "BYE");
        }
      }
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Amol
Advanced
Posts: 176
Joined: Mon May 29, 2006 12:00 am

Re: Grid in Rectangle tool

Post by Amol » Tue Nov 25, 2014 10:55 am

Hi Steema,

Thanks for your reply, We want to set the column size according to the text written in that column. Suppose first column have text of 100 character and second column column contains 10 character the column size should be accordingly. and can we wrap the text written in it.We are waiting for your response.



Thanks

Plano
Last edited by Amol on Tue Nov 25, 2014 11:29 am, edited 1 time in total.

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Grid in Rectangle tool

Post by Christopher » Tue Nov 25, 2014 11:06 am

Amol wrote: Thanks for your reply, We want to set the column size according to the text written in that column. Suppose first column have text of 100 character and second column column contains 10 character the column size should be accordingly. We are waiting for your response.
You can use the Graphics3D.TextWidth() method to measure the length of strings, e.g.

Code: Select all

float width = g.TextWidth("BYE");
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply