I'd like to draw a custom 2nd axis that's tied to data but .

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
dunion
Newbie
Newbie
Posts: 19
Joined: Fri Mar 12, 2004 5:00 am

I'd like to draw a custom 2nd axis that's tied to data but .

Post by dunion » Tue Mar 03, 2009 7:36 pm

this one woud scale differently. It has to be tied to the existing data so that the zooms and such work.

For example let's say I have 50 points and the first axis labels them from 800-1000 in steps of 4 (horizontal axes with ticks). For example, let's say the default ticks are going to be every 5 points.

I want another axes, tied to the same data, that is also horizontal, that labels the same points differently, for example from 100-250 in steps of 3 and I want a tick every 3 points along this axes. I might have this float a bit above or below where the other horizontal axes is (say, for example, +5% up on the drawing area (above) the other axis.

I don't want the 'first' one to try to 'rescale'; that is the start and end are 'the same', this is just two representations of the 'same data' (for example different units, etc.).

If I custom draw, then I have to handle all the zoom and redraw code manually (which I can do) but I was wondering if there is a default way to do this.

dunion
Newbie
Newbie
Posts: 19
Joined: Fri Mar 12, 2004 5:00 am

Got it - add a new line

Post by dunion » Tue Mar 03, 2009 7:47 pm

I added a new line with a 'y' value of 0 for each of the points in the first line and an 'x' value associated with the new range I want. Then I made a custom horizontal axis for that line and added it to the chart. Looks really ugly right now but that's all a matter of moving stuff around.

Steema.TeeChart.Axis axis1 = new Steema.TeeChart.Axis(false, false, tChart1.Chart);
tChart1.Axes.Custom.Add(axis1);
line2.CustomHorizAxis = axis1;
axis1.StartPosition = 0;
axis1.EndPosition = 100;
axis1.Automatic = false;

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Post by Sandra » Wed Mar 04, 2009 12:02 pm

Hi dunion,

Custom axes don't support zoom. You have to do that manually as told here.

Also, for add extra axes you can see Tutorial4 for NET, on how to add a new axis, and changing some properties of axes.

If you have any problems, please tell exactly we must do, because we can reproduce here your issue.
Best Regards,
Sandra Pazos / 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

dunion
Newbie
Newbie
Posts: 24
Joined: Fri Dec 19, 2008 12:00 am

Re: I'd like to draw a custom 2nd axis that's tied to data but .

Post by dunion » Thu Jul 16, 2009 4:23 pm

That didn't do quite what I want. What I want is pretty simple.
Two axes for the same data with different units. Say the data is a bunch of values.
The 'bottom axes' can be 'automatic' and track the values used for the curve data.
The 'top axes' needs to be different non-related units but still there is a one-to-one
correspondence that I know.

100 200 300 400 500 ... etc.
---------+-----+----+-----+----+----------------------
100

80

70

60

50 (some curve here)
------+-----+----+---+---+---+---+------------------
5 10 15 20 30 40 50...


What I've tried if from your last reply and from the sample, didn't quite do what I was looking for. Do you have a sample of this?

Thanks.

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: I'd like to draw a custom 2nd axis that's tied to data but .

Post by Yeray » Fri Jul 17, 2009 11:51 am

Hi dunion,

If I understand well, you should assign both top and bottom axis to your series and then modify one of the axis labels at OnGetAxisLabel event knowing the relation. For example with a relation 1x100:

Code: Select all

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

        private void InitializeChart()
        {
            chartController1.Chart = tChart1;

            tChart1.Aspect.View3D = false;
            tChart1.Legend.Visible = false;

            Line line1 = new Line(tChart1.Chart);
            line1.FillSampleValues(25);

            line1.HorizAxis = HorizontalAxis.Both;

            tChart1.GetAxisLabel += new GetAxisLabelEventHandler(tChart1_GetAxisLabel);

        }

        void tChart1_GetAxisLabel(object sender, GetAxisLabelEventArgs e)
        {
            if (sender == tChart1.Axes.Top)
            {
                e.LabelText = (Convert.ToDouble(e.LabelText) * 100).ToString();
            }
        }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

dunion
Newbie
Newbie
Posts: 24
Joined: Fri Dec 19, 2008 12:00 am

Re: I'd like to draw a custom 2nd axis that's tied to data but .

Post by dunion » Fri Jul 17, 2009 1:10 pm

Is there an other way to do this?
I don't always want to show this second axis: it depends on what button the user used to start drawing on this chart as I use it for a lot of different drawing scenarios, so it shouldn't be a general event handler.

One option is to add and remove the event handler all the time - which could become a threading challenge, or have some locked flag for mode.

Also my code has a couple of tcharts, and the functions I use pass in a pointer to a tchart object and do stuff with one - so I'd rather not hook up an event handler to a specific chart by name if I can avoid it. Otherwise I'd have to have handlers for each of the charts and a bunch of locked mode flags to check for every axis label, and that could effect performance (I'm taking live data for this chart).

dunion
Newbie
Newbie
Posts: 24
Joined: Fri Dec 19, 2008 12:00 am

Re: I'd like to draw a custom 2nd axis that's tied to data but .

Post by dunion » Fri Jul 17, 2009 1:45 pm

I did try that suggested method. I explicitly constructed the handler for my chart and put the suggested code, the only other thing I put was a check to verify (in the tChart2_GetAxisLabel) what 'tab' of a tab set I was on. Then after putting a break point in the debugger on the e.LabelText = ...
inside the
if (sender == tChart2.Axes.Top) {

I never hit this breakpoint and my graph turns into a white screen with a big red 'X' in the middle.

dunion
Newbie
Newbie
Posts: 24
Joined: Fri Dec 19, 2008 12:00 am

Re: I'd like to draw a custom 2nd axis that's tied to data but .

Post by dunion » Fri Jul 17, 2009 1:48 pm

I should also mention that if I just set
refLine.HorizAxis = Steema.TeeChart.Styles.HorizontalAxis.Both;
I never see an axis on top.

refLine is a 'FastLine'.

I think there is one bug fix release since I updated this version. If this is a bug that can be solved by an update, either to the latest patch version or the 2009 version also let me know.

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

Re: I'd like to draw a custom 2nd axis that's tied to data but .

Post by Narcís » Fri Jul 17, 2009 2:13 pm

Hi dunion,

In that case I think the easiest option is passing the labels you want at the top axis to the Add method as shown in the code snippet below and then set the Labels.Style you want for each value.

Code: Select all

			Steema.TeeChart.Styles.FastLine fastLine1 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);

			Random y = new Random();

			for (int i = 0; i < 10; i++)
			{
				double tmp = y.Next();
				fastLine1.Add(tmp, "point " + i.ToString());
			}

			fastLine1.HorizAxis = Steema.TeeChart.Styles.HorizontalAxis.Both;
			tChart1.Axes.Top.Visible = true;
			tChart1.Axes.Top.Labels.Style = Steema.TeeChart.AxisLabelStyle.Text;
			tChart1.Axes.Bottom.Labels.Style = Steema.TeeChart.AxisLabelStyle.Value;
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

dunion
Newbie
Newbie
Posts: 24
Joined: Fri Dec 19, 2008 12:00 am

Re: I'd like to draw a custom 2nd axis that's tied to data but .

Post by dunion » Mon Jul 20, 2009 6:42 pm

Thanks.
I tried this but still don't see any top axis. I did some debugging, while stepping through I get four kinds of cases for the events for the top axis. In this case I only had one line on the chart but usually I have at least two different lines, at least one a 'line' and one a 'fastline', on this tChart object instance.

tChart2_GetAxisLabel() {
if (sender == tChart2.Axes.Top) {
...
One has e.LabelText = "";
One has e.LabelText = "0".
Another has a single value that looks like my x-axis values
Another has a comma-separated value-pair that has an integer and maybe my y-axis values.

Should I try to set e.LabelText back to a string[] array like 'point number, text' rather than just a single text value?

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: I'd like to draw a custom 2nd axis that's tied to data but .

Post by Yeray » Tue Jul 21, 2009 10:24 am

Hi dunion,

Note that the code that Narcís posted above doesn't use OnGetAxisLabels nor any other event. Could you try that code in a simple new application to see if the axes are shown in a similar way than what you expected?
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

dunion
Newbie
Newbie
Posts: 24
Joined: Fri Dec 19, 2008 12:00 am

Re: I'd like to draw a custom 2nd axis that's tied to data but .

Post by dunion » Tue Jul 21, 2009 1:10 pm

I tried that first and didn't see anything on the top of the chart, that's when I thought he might also be expecting me to do stuff with 'ongetaxis'. No luck there either.

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

Re: I'd like to draw a custom 2nd axis that's tied to data but .

Post by Narcís » Tue Jul 21, 2009 1:46 pm

Hi dunion,

Thanks for the info. Can you please attach a simple example project we can run "as-is" to reproduce the problem here and let us know the exact TeeChart version you are using?

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

dunion
Newbie
Newbie
Posts: 24
Joined: Fri Dec 19, 2008 12:00 am

Re: I'd like to draw a custom 2nd axis that's tied to data but .

Post by dunion » Tue Jul 21, 2009 1:53 pm

I haven't had time to create a separate test project, and today is pretty straight out, I'll try to over the next couple of days.
I have a fairly simple project in terms of teechart, at least I thought so. I have two tabs each with a tchart, and I add or remove lines from whichever tab is currently 'visible'

So i could add a line to one chart, view the other tab, add a line to it, and go back to the 1st chart and clear or add another line to it.

I have general data (that may be live/continuous on one line and a 'static' set of data on another comparison line).

I have an axis on the bottom that is 'automatic' based on the x-values, i want another 'x-value' axis on top with a different set of numbers that i can compute via a formula and lookup array based on the x-value axis

Teechart version is
3.5.3425.20245

The chart is otherwise fairly 'generic', 2d, and using one of the built-in themes (and the user can change that theme but that doesn't effect the behavior in any way).

I tried the text as suggested and didn't see the top line. I tried creating a new line with a bright color and putting it on top, I can do that, and for a while I was trying to use a new line on top (a new fastline) with it's only axis on top, and values based on teh 2nd set I wanted to use - then make the line itself 'transparent' so I didn't see it.

Post Reply