Managing Axis Increment

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
amol
Advanced
Posts: 231
Joined: Tue Mar 29, 2005 5:00 am

Managing Axis Increment

Post by amol » Wed Aug 12, 2015 1:20 pm

Hi Steema support,
We have prepared the demo for managing the axis scaling in TChart . In this demo we have given the following inputs for X-axis ,Y-axis and Y-Alternate axis are mentioned below:-
tChart1.Axes.Bottom.Automatic = false;
tChart1.Axes.Bottom.Minimum = -50.0;
tChart1.Axes.Bottom.Maximum = 650;
tChart1.Axes.Bottom.Increment = 50;
tChart1.Axes.Bottom.MinorTicks.Length = 4;

tChart1.Axes.Left.Automatic = false;
tChart1.Axes.Left.Minimum = 3870;
tChart1.Axes.Left.Maximum = 4010;
tChart1.Axes.Left.Increment = 50;
tChart1.Axes.Left.MinorTicks.Length = 4;

tChart1.Axes.Right.Automatic = false;
tChart1.Axes.Right.Minimum = -50.0;
tChart1.Axes.Right.Maximum = 550;
tChart1.Axes.Right.Increment = 50;
tChart1.Axes.Right.MinorTicks.Length = 4;
tChart1.Axes.Right.Grid.Visible = false;

The below figure(1) shows according to all above input but not same as below figure (2).
Our max, min, tick increment and total no of tick are same but minor per major tick are not. So kindly let us know how to implement minor per major ticks in TChart 2012.
2015-08-12_182102.png
Figure-1
2015-08-12_182102.png (68.9 KiB) Viewed 25067 times
2015-08-12_174302.png
Figure-2
2015-08-12_174302.png (11.2 KiB) Viewed 25057 times
In figure-2, each minor tick has increment of 50, so is there any way in Steema Tchart to set increment of axis with respect to minor tick.
So, kindly suggest how to manage bottom axis of (Fig-1) according to (Fig-2) in TChart 2012 version, with respect to labels, ticks, minimum value, maximum value and grid lines of the axis.

Thanks
PlanoResearch
Attachments
ManageAxis.rar
DemoProject
(97.7 KiB) Downloaded 963 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Managing Axis Increment

Post by Narcís » Wed Aug 12, 2015 2:25 pm

Hi PlanoResearch,

I'm not sure about which is your exact question. However, you can have bottom axis in the example you sent (figure1) as in figure2 example using this code:

Code: Select all

          tChart1.Axes.Bottom.SetMinMax(-50.0, 650);
          tChart1.Axes.Bottom.Increment = 200;
          tChart1.Axes.Bottom.IncrementOffset = 50;
          tChart1.Axes.Bottom.Labels.OnAxis = true;
          tChart1.Axes.Bottom.MinorTicks.Length = 4;
You can set Increment relative to the number of minor ticks using something like this:

Code: Select all

          tChart1.Axes.Bottom.Increment = (tChart1.Axes.Bottom.MinorTickCount + 1) * 50;
Is this what you were looking for? Otherwise please provide more detailed information about your exact requirements.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

amol
Advanced
Posts: 231
Joined: Tue Mar 29, 2005 5:00 am

Managing Axis Increment

Post by amol » Fri Aug 14, 2015 9:49 am

Thanks for reply,
But we have one more query regarding Axis management.

We are using the following inputs for X-axis,Y-axis and Y-Alternate axis are mentioned below:-
tChart1.Axes.Bottom.Minimum = 200;
tChart1.Axes.Bottom.Maximum = 3000;
tChart1.Axes.Bottom.IncrementOffset = 200;
tChart1.Axes.Bottom.Increment = 1000;
tChart1.Axes.Bottom.MinorTickCount = 4;

tChart1.Axes.Left.Minimum = 3870;
tChart1.Axes.Left.Maximum = 4010;
tChart1.Axes.Left.Increment = 10;
tChart1.Axes.Left.MinorTicks.Length = 5;

tChart1.Axes.Right.Minimum = -50;
tChart1.Axes.Right.Maximum = 550;
tChart1.Axes.Right.Increment = 50;
tChart1.Axes.Right.MinorTicks.Length 4;
tChart1.Axes.Right.Grid.Visible = false;
The below figure(1) shows according to all above input but not same as below figure (2).
As shown in below figure-1, the left Axis label start showing from initial position which looks correct but on the other hand labels of bottom axis not start showing from initial position of axis.
We want to show axis labels of all axis from initial position as shown in Fig.2
Figurre1.png
Figure 1
Figurre1.png (5.56 KiB) Viewed 24987 times
Figure2.png
Figure 2
Figure2.png (5.16 KiB) Viewed 24984 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Managing Axis Increment

Post by Narcís » Fri Aug 14, 2015 9:58 am

Hello,

What about setting this?

Code: Select all

      tChart1.Axes.Bottom.Labels.OnAxis = true;
I can not reproduce the problem with the project you sent and modifying axes settings according to your last post, complete code available below.

Code: Select all

    public partial class Form1 : Form
    {
        double x0 = -15, x1 = 15, x2 = 22.5, x3 = 600, y0 = -15, y1 = 25, y2 = 35, y3 = 650;

        Line line;
        Line lineFlow;

        public Form1()
        {
            InitializeComponent();            
            InitializeChart();
        }

        /// <summary>
        /// creates chart components
        /// </summary>
        private void InitializeChart()
        {
          tChart1.Panel.Gradient.StartColor = Color.MistyRose;
          tChart1.Panel.Gradient.MiddleColor = Color.MistyRose;
          tChart1.Aspect.View3D = false;
          line = new Line(tChart1.Chart);
          lineFlow = new Line(tChart1.Chart);
          line.Add(x0, y0);
          line.Add(x1, y1);
          line.Add(x2, y2);
          line.Add(x3, y3);

          lineFlow.Add(x0, y0);
          lineFlow.Add(x1, y1);
          lineFlow.Add(x2, y2);
          lineFlow.Add(x3, y3);
          lineFlow.VertAxis = Steema.TeeChart.Styles.VerticalAxis.Right;

          lineFlow.Color = Color.Red;
          line.Color = Color.Red;
          tChart1.Legend.Visible = true;

          tChart1.Axes.Bottom.SetMinMax(200, 3000);
          tChart1.Axes.Bottom.Increment = 200;
          tChart1.Axes.Bottom.IncrementOffset = 1000;
          tChart1.Axes.Bottom.Labels.OnAxis = true;
          tChart1.Axes.Bottom.MinorTicks.Length = 4;

          tChart1.Axes.Left.SetMinMax(3870, 4010);
          tChart1.Axes.Left.Increment = 10;
          tChart1.Axes.Left.MinorTicks.Length = 5;

          tChart1.Axes.Right.SetMinMax(- 50.0, 550);
          tChart1.Axes.Right.Increment = 50;
          tChart1.Axes.Right.MinorTicks.Length = 4;
          tChart1.Axes.Right.Grid.Visible = false;

      #region TeeChart Properties

      tChart1.Aspect.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
      tChart1.Panel.Color = Color.White;
      tChart1.Panel.Gradient.Visible = false;
      tChart1.Walls.Back.Gradient.Visible = false;
      tChart1.Walls.Back.Color = tChart1.Panel.Color;
      tChart1.Walls.Back.Transparency = 0;
      tChart1.Chart.Panning.Allow = Steema.TeeChart.ScrollModes.None;
      tChart1.Zoom.Direction = Steema.TeeChart.ZoomDirections.None;
      tChart1.Header.TextAlign = StringAlignment.Center;
      tChart1.Walls.Back.Visible = false;
      tChart1.Walls.Back.Visible = false;
      tChart1.Axes.Left.Title.Text = "Y-Axis";
      tChart1.Axes.Bottom.Title.Text = "X-Axis";

      #endregion
    }

        private void tChart1_DoubleClick(object sender, EventArgs e)
        {
            tChart1.ShowEditor();
        }
    }
If problem persists please attach a simple example project we can run "as-is" to reproduce the problem here.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

amol
Advanced
Posts: 231
Joined: Tue Mar 29, 2005 5:00 am

Managing Axis Increment

Post by amol » Mon Aug 17, 2015 6:14 am

Hi Steema Support,

Thanks for your reply.

We are using the "OnAxis" property as shown below but it does not do anything.
tChart1.Axes.Bottom.Labels.OnAxis = true;
Labels at the corner.png
Image
Labels at the corner.png (41.11 KiB) Viewed 24943 times
We are attaching a new demo for better understanding.Please provide any solution asap.
Thanks in advance.
ManageAxis.rar
Demo
(45.68 KiB) Downloaded 975 times
Thanks
PlanoResearch

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Managing Axis Increment

Post by Marc » Mon Aug 17, 2015 10:50 am

Hello,

OnAxis won't work in this case as it is looking to plot a regularly incremented label. I've added a feature request, http://bugs.teechart.net/show_bug.cgi?id=1272.

In the meantime there are other options to better control the Label output for non-standard requirements. Here are a couple:

This will add the label you require. It uses the TChart AfterDraw event:

Code: Select all

using Steema.TeeChart;
using System.Reflection;

private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
    //set x position for new label
    int x = tChart1.Axes.Bottom.CalcPosValue(tChart1.Axes.Bottom.Minimum);

    //tChart1.Axes.Bottom.Labels.position (here the Label y coordinate) is protected so need alternative technique for y...
    //(We'll add publicly scoped access for this variable for future releases)
    AxisLabels tmpLabels = new AxisLabels(tChart1.Axes.Bottom);
    FieldInfo privateField = tmpLabels.GetType().GetField("position", BindingFlags.NonPublic | BindingFlags.Instance);
    int y = (int)privateField.GetValue(tChart1.Axes.Bottom.Labels);

    string label = tChart1.Axes.Bottom.Minimum.ToString("#");

    //output text
    g.TextOut(x - ((int)Math.Round(g.TextWidth(label) / 2)), y, label);
}
This option allows you to set the exact labels you require from scratch, overriding TeeChart's own choice for labels:

Code: Select all

tChart1.Axes.Bottom.Labels.Items.Add(tChart1.Axes.Bottom.Minimum, tChart1.Axes.Bottom.Minimum.ToString());

double incr = 500;
double labelvalue = tChart1.Axes.Bottom.Minimum + incr; //increment in steps of 500

while ((tChart1.Axes.Bottom.Minimum + labelvalue + incr) < tChart1.Axes.Bottom.Maximum)
{
    tChart1.Axes.Bottom.Labels.Items.Add(labelvalue, labelvalue.ToString());
    labelvalue += incr;
}
I hope that may be of help.
Regards,
Marc Meumann
Steema Support

amol
Advanced
Posts: 231
Joined: Tue Mar 29, 2005 5:00 am

Re: Managing Axis Increment

Post by amol » Sat Aug 22, 2015 4:48 am

Hi Steema Support,

Thanks for your reply. its works fine for the labels.

But we are facing one more problem i.e. shown in Figure 1. It shows small space between axis line and Grid line(Starting grid line) why? we are using MinimumOffset, MaximumOffset and IncrementOffset value 0(zero).
Img1.png
Figure 1
Img1.png (27.82 KiB) Viewed 24889 times
We want no space there as shown in figure 2 below.there is no space shown and grid line created with uniform interval.
Img2.png
Img2.png (8.9 KiB) Viewed 24889 times

please provide any solution. Thanks in advance.

Thanks
PlanoResearch

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Managing Axis Increment

Post by Narcís » Mon Aug 24, 2015 8:08 am

Hello,

Could you please attach a simple example project we can run "as-is" to reproduce the problem here?

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

amol
Advanced
Posts: 231
Joined: Tue Mar 29, 2005 5:00 am

Re: Managing Axis Increment

Post by amol » Mon Aug 31, 2015 1:41 pm

Hi Steema Support,

We are attaching a Demo project for the same and will reproduce the problem(It shows small space between axis line and Grid line).

According to my understanding When we set line.Pointer.visible=True; then it shows the problem as given in demo.

Kindly provide any solution asap.

Thanks in advance.

Thanks
PlanoResearch
ManageAxis.rar
Demo
(57.31 KiB) Downloaded 964 times

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

Re: Managing Axis Increment

Post by Christopher » Mon Aug 31, 2015 1:48 pm

Hello,
amol wrote:According to my understanding When we set line.Pointer.visible=True; then it shows the problem as given in demo.

Kindly provide any solution asap.
I think you can resolve this with:

Code: Select all

line.Pointer.InflateMargins = false;
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: 231
Joined: Tue Mar 29, 2005 5:00 am

Re: Managing Axis Increment

Post by amol » Mon Aug 31, 2015 2:04 pm

Thanks!!! Christopher it works.

Post Reply