Page 1 of 1

static axis grid when zooming

Posted: Sun Jul 01, 2012 12:43 pm
by 14048025
Hi,

I'm using the top axes in a chart and applied zooming in and out manually using the axis Minimum & Maximum properties.
This works just fine for me.
The issue is that when zooming in or out the axis grid (together with ticks and labels) change position to their new position. I wish to have the axis grid remain static (i.e. not move at all) and only have their labels change to their new values (according to the position of the grid line relative to the new minimum value).

is there any built-in way (or any way at all) to achieve this ?

Thanks
Yair

Re: static axis grid when zooming

Posted: Thu Jul 05, 2012 4:23 pm
by 10050769
Hello Yair,

I understand, you want grid and ticks of Top axis, don't move when you do zoom. If is this, I recommend you consider the definition to zoom of TeeChart where expliat that Zooms the entire Chart. Increasing the value of Zoom brings the entire Chart towards the viewer. 'In Chart' zoom will still function by mouse dragging within the Chart area and is distinct from whole Chart zooming. Therefore, probably we can not achieve as you want to easy way. On the other hand, If not, please try to explain again do you want achieve. Moreover, you can disable the zoom in Top Axis, using drections property of Zoom and I think can help you. You can do something as next:

Code: Select all

  tChart1.Zoom.Direction = ZoomDirections.Vertical;
This allow you only do zoom in Left Axis. If it solution doesn't like, please let me know.

Thanks,

Re: static axis grid when zooming

Posted: Tue Jul 10, 2012 6:46 pm
by 14048025
Hi Sandra,

Thank you for your reply!

I'll try to further explain what i'm looking for. perhaps the term "zoom" is confusing here.
Basically i set the axis.Minimum & axis.Maximum to different values, which achieve a sense of "zooming" of the entire chart to the viewer. (I applied this to the mouse wheel scroll event).
The thing is that when doing so (and BTW also with your zooming) the axis's grid lines positions are recalculated (I don't know according to what). I think it would have been neater (or at least a nice added feature) if the grid lines did not move at all when setting the new Minimum/Maximum and only have their label values recalculated to show their new position on the viewable chart (which now start from a different point. i.e. axis.Minimum).

Thanks
Yair

Re: static axis grid when zooming

Posted: Mon Jul 16, 2012 8:13 am
by narcis
Hi Yair,

I think I understand what you are looking for. The only way I can think of for now is manually adding custom labels every time the chart is zoomed so that you can control the exact numbers of labels displayed. For example:

Code: Select all

    public Form1()
    {
      InitializeComponent();
      InitializeChart();
    }
    
    private void InitializeChart()
    {
      tChart1.Dock = DockStyle.Fill;
      tChart1.Aspect.View3D = false;

      tChart1.Series.Add(new Steema.TeeChart.Styles.Line()).FillSampleValues();
      tChart1[0].HorizAxis = Steema.TeeChart.Styles.HorizontalAxis.Top;

      DrawTopLabels();

      tChart1.Zoomed += new EventHandler(tChart1_Zoomed);
      tChart1.UndoneZoom += new EventHandler(tChart1_UndoneZoom);
    }

    void tChart1_UndoneZoom(object sender, EventArgs e)
    {
      DrawTopLabels();
    }

    void tChart1_Zoomed(object sender, EventArgs e)
    {
      DrawTopLabels();
    }

    private void DrawTopLabels()
    {
      tChart1.Draw();

      int numLabels = 10;
      double min = tChart1.Axes.Top.Minimum;
      double max = tChart1.Axes.Top.Maximum;
      double range = max - min;
      double increment = range / numLabels;

      tChart1.Axes.Top.Labels.ValueFormat = "#.##";
      tChart1.Axes.Top.Labels.Items.Clear();

      for (double i = min; i < max; i = i + increment)
      {
        tChart1.Axes.Top.Labels.Items.Add(i);
      }
    }
If that's not what you need don't hesitate to let us know.

Re: static axis grid when zooming

Posted: Tue Jul 17, 2012 1:08 pm
by 14048025
Thanks Narcis!

That is exactly what i was looking for.

only one slight issue with it:
for some reason when drawing the lables manually as you suggested, the label's color seems to default always to black. though i've set previously:
tChart1.Axes.Top.Labels.Font.Brush.Color = Color.White;
This is important for me since i've set the chart panel background to black (tChart1.Panel.Brush.Color = Color.Black;)
Any way i can turn them back to white?

Much Obliged,
Yair

Re: static axis grid when zooming

Posted: Tue Jul 17, 2012 2:25 pm
by narcis
Hi Yair,

Yes, you need to set the color for each label item as shown in the All Features\Welcome !\Axes\Labels\Custom labels example at the features demo available at TeeChart's program group. For example:

Code: Select all

        (tChart1.Axes.Top.Labels.Items.Add(i)).Font.Color = Color.White;

Re: static axis grid when zooming

Posted: Wed Jul 18, 2012 12:00 pm
by 14048025
Great. Thanks!

Yair