Recent

Author Topic: [SOLVED] Scaling 2 Y axies  (Read 5458 times)

Hopestation

  • Full Member
  • ***
  • Posts: 181
[SOLVED] Scaling 2 Y axies
« on: March 30, 2013, 05:44:25 pm »
Hi.

This is the first time I have tried using a TAChart component, and despite looking at the Wiki TAChart examples and TAChart Documentation I can't get the correct scale for the right hand axis.

I have three series, 2 of which use the left Y axis and have a maximum value of 1000. The third has a maximum of 3 and uses the Right Y axis.

I can't get a scale of 3 on the right axis. It copies the left axis.

I have added LeftAxisTransformations and set it to LeftAxisTransformationsAutoscaleaxistransform1 then done the same for the right axis.

Changing the range in each axis does not work.

What am I doing wrong?
« Last Edit: April 01, 2013, 07:03:45 pm by Hopestation »

wp

  • Hero Member
  • *****
  • Posts: 13485
Re: Scaling 2 Y axies
« Reply #1 on: March 30, 2013, 06:18:04 pm »
Have a look at http://wiki.lazarus.freepascal.org/TAChart_Tutorial:_Dual_y_axis,_Legend - it gives step-by-step instructions of exactly what you want to do.

Did you use the correct AxisIndex for each series?

Hopestation

  • Full Member
  • ***
  • Posts: 181
Re: Scaling 2 Y axies
« Reply #2 on: March 30, 2013, 08:07:36 pm »
Hi WP.

Yes, it was that link that I followed and found the need for the AxisTransformations.

I have used the following code to set the scales:

  Chart.AxisList[0].Range.Max := 1000;        // Left Y Axis    - axis 0
  Chart.AxisList[1].Range.Max := Count;      // X Axis           - axis 1
  Chart.AxisList[2].Range.Max := 3;             // Right Y Axis   - axis 2

Series1 AxisIndexY and Series2 AxisIndexY  are set to 0
Series3 AxisIndexY  is set to 2

This works correctly for  the x axis which is set to the value, Count, which is determined earlier in the program. It sets the left Y axis to 1000, but the right Y axis is also set to 1000.

Something is wrong but I don't know what.

wp

  • Hero Member
  • *****
  • Posts: 13485
Re: Scaling 2 Y axies
« Reply #3 on: March 30, 2013, 10:17:11 pm »
Of course I cannot see here what you are doing wrong. If you follow the tutorial the two axes behave correctly. Maybe you can strip down your chart to a simple demo project which you post here.

Hopestation

  • Full Member
  • ***
  • Posts: 181
Re: Scaling 2 Y axies
« Reply #4 on: April 01, 2013, 04:27:21 pm »
Hi WP.

I have now not just read the articles that I mentioned before but followed them to create the programs, which worked.

However, the population example is not very realistic. It only has 100 lines of data, so when the program runs, the chart appears immediately.

My data consists of between 5000 and 25000 lines of data which are calculated in the program and then loaded into the three series in real time.

Calculating the smallest number number of lines takes around 5 seconds to complete and all this time the chart is flashing as the chart seems to update every time a new line of data is created. Also, the scale numbering increases as the calculated values get larger. This is not what I want.

I know what the final maximum values of all the axes will be before the calculations start, so I want to set these in the program. I have turned off the visibility of each series until all values are calculated in attempt to stop the flickering, but it still happens.

If this was Excel or Scalc I would assign my columns of data to the axes then specify the maximum and minimum values for each axis. I cannot find out how to set the scales manually in this chart.

Can you explain how I do it?

wp

  • Hero Member
  • *****
  • Posts: 13485
Re: Scaling 2 Y axies
« Reply #5 on: April 01, 2013, 06:23:14 pm »
In the attached demo with 25000 data, the chart appears within a snap... I cannot reproduce your problem.

To avoid intermediate repaints of the chart during your calculation you could
  • call BeginUpdate before and EndUpdate of each ChartSource before and after the calculation, or
  • store the results in arrays (not in the internal ListSource of each series) and use UserDefinedChartSources as an interface between the arrays and the series. After the calculation set the PointsNumber of each UserDefinedChartSource to the number of data points and call UserDefinedChartSource.Reset.

In both cases, your chart appears immediately, but after some delay caused by the time of your calculation. If you want to see intermediate results during the calculation and know the axis ranges in advance (e.g. 0-1000 for the left axis, 0-3 for the right axis) you should use the Range parameter of each axis, as you did. But did you call UseXMin/UseXMax?

Hopestation

  • Full Member
  • ***
  • Posts: 181
Re: [SOLVED] Scaling 2 Y axies
« Reply #6 on: April 01, 2013, 07:09:47 pm »
Although I could see the attachment symbol in your message I couldn't open it.

However, the good news is that I have solved the problems.

The slow running was because I was writing the results of each calculation into a memo.

Commenting this out gave an almost instantaneous response.

More good news is that I can now set the scales on both axes at design time and they don't change during run time.

The Bad news is that I don't know what I did differently now compared with what I was doing before.

Thanks for your help.

wp

  • Hero Member
  • *****
  • Posts: 13485
Re: [SOLVED] Scaling 2 Y axies
« Reply #7 on: April 01, 2013, 08:19:57 pm »
Quote
Although I could see the attachment symbol in your message I couldn't open it.
Working with me...

 

TinyPortal © 2005-2018