Page 1 of 1

True scale

Posted: Sat Jul 29, 2006 6:26 pm
by 8129599
Hi,

if I want to display (and print) an x-y-chart with for example a circle represented as x=r.cos(angle) and y= r.sin(angle) but without a distortion
so that the user sees a 'real' circle, how can I do that?

Best regards and thanks for any help.

Tobias

Posted: Mon Jul 31, 2006 10:37 am
by narcis
Hi Tobias,

To get a real circle you could use something as shown in the All Features\Welcome !\Axes\Isometric axes example at the features demo available at TeeChart's program group.

For the series what would you like to use, points, a line, ...?

Posted: Mon Jul 31, 2006 11:55 am
by 8129599
Hi Narcis,

thank you for the answer!

I generally use TFastLine-Series.

Regards, Tobias

Posted: Mon Jul 31, 2006 12:12 pm
by 8129599
Hi Narcis,

sorry, but I cannot find this topic in my program group.
( I am using TeeChart .NET 1.1.2004.16952 with Delphi 2006)

Regard Tobias

Posted: Mon Jul 31, 2006 2:22 pm
by narcis
Hi Tobias,

Ok, you can use something like this:

Code: Select all

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Steema.TeeChart;
using System.Runtime.InteropServices;

namespace CircledShape
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private static short HORZSIZE = 4;     // Horizontal size in millimeters 
    private static short VERTSIZE = 6;     // Vertical size in millimeters 
    [DllImport("gdi32.dll")]
    private static extern Int32 GetDeviceCaps(IntPtr hdc, Int32 capindex);

    private void Form1_Load(object sender, EventArgs e)
    {
      
      fastLine1.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.None;
      fastLine1.YValues.Order = Steema.TeeChart.Styles.ValueListOrder.None;
      
      for (double angle = 0; angle < 2*Math.PI; angle=angle+0.001)
      {       
        fastLine1.Add(Math.Cos(angle), Math.Sin(angle));  
      }                  

      tChart1.Axes.Left.SetMinMax(-1.25, 1.25);
      tChart1.Axes.Bottom.SetMinMax(-1.25, 1.25);

      //Trick to force the chart being drawn so that isometric axes can be calculated
      Bitmap bmp = tChart1.Bitmap;

      MakeIsometric(fastLine1);
    }

    private void MakeIsometric(Axis vertical, Axis horizontal)
    {
      if ((vertical.Chart.Width > 0) && (vertical.Chart.Height > 0))
      {
        // setup values
        double xrange = horizontal.Maximum - horizontal.Minimum;
        double yrange = vertical.Maximum - vertical.Minimum;
        double tmpx = xrange / (double)vertical.Chart.Width;
        double tmpy = yrange / (double)vertical.Chart.Height;

        Screen screen = Screen.FromControl(this);
        Graphics g = Graphics.FromHwnd(this.Handle);
        IntPtr hptr = g.GetHdc();
        double xyscreen = GetDeviceCaps(hptr, HORZSIZE) * screen.Bounds.Height;
        xyscreen /= (double)GetDeviceCaps(hptr, VERTSIZE) * screen.Bounds.Width;
        g.ReleaseHdc(hptr);
        g.Dispose();

        tmpy *= xyscreen;
        double offset = 0.0;
        if (tmpx > tmpy)
        {
          if (tmpy != 0.0)
          {
            offset = 0.5 * (yrange * tmpx / tmpy - yrange);
            vertical.SetMinMax(vertical.Minimum - offset, vertical.Maximum + offset);
          }
        }
        else if (tmpx < tmpy)
        {
          if (tmpx != 0.0)
          {
            offset = 0.5 * (xrange * tmpy / tmpx - xrange);
            horizontal.SetMinMax(horizontal.Minimum - offset, horizontal.Maximum + offset);
          }
        }
      }
    }

    private void MakeIsometric(Steema.TeeChart.Styles.Series series)
    {
      MakeIsometric(series.GetVertAxis, series.GetHorizAxis);
    }

    private void tChart1_Zoomed(object sender, EventArgs e)
    {
      MakeIsometric(fastLine1);
    }

    private void tChart1_UndoneZoom(object sender, EventArgs e)
    {
      MakeIsometric(fastLine1);
    }

    private void tChart1_Scroll(object sender, EventArgs e)
    {
      MakeIsometric(fastLine1);
    }
  }
}