### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: TAChart Logarithmic and Linear scale on one Chart  (Read 5317 times)

#### markostarko

• New Member
• Posts: 10
##### TAChart Logarithmic and Linear scale on one Chart
« on: July 27, 2012, 10:25:28 am »
Hello!

I'am working on project for process control, and have been trying to plot logarithmic scale and linear scale to one chart. However i made Chart whit two axis and assign logarithmical transformation to one of them, but how to scale it propperly. What is AxisindexY property and how does it work.

Also is it possible to draw vertical line on chart and get Y axis vale from line position?

« Last Edit: July 27, 2012, 10:28:56 am by markostarko »

#### wp

• Hero Member
• Posts: 7332
##### Re: TAChart Logarithmic and Linear scale on one Chart
« Reply #1 on: July 27, 2012, 01:06:41 pm »
I am not quite sure what you mean: Do you, for example, want to have several curves in the chart, some drawn with a linear scale in the left axis, and the other ones with a log scale on the right axis?

Have a look at the example in demos\axistransf. Moreover, there are several postings in this forum (board "Graphics - TAChart") which refer to logarithmic axis transforms.

You have to assign the AxisIndexY of the log series to the index of the logarithmic y axis (you see that in the object inspector tree). And, of course, you need a LogarithmTransform that is assigned to this axis.
« Last Edit: July 27, 2012, 01:08:12 pm by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

#### markostarko

• New Member
• Posts: 10
##### Re: TAChart Logarithmic and Linear scale on one Chart
« Reply #2 on: July 27, 2012, 03:04:44 pm »
I done that now  but still right axis title is not shown, what about vertical line that would be cursor for graph and also show current values. How can i get series value at cursor position from x,y on mouse move. Would situation change whit logarithmic transform.

If anybody have good example for this situation getting y value from logarithmic chart on mouse move pleas explain how it's done.

I read everything available on forum, but it's not all clear to me. It's my first project whit lazarus and at beginning it went so well, but now whit plotting part i have some difficulties.

• Global Moderator
• Hero Member
• Posts: 687
##### Re: TAChart Logarithmic and Linear scale on one Chart
« Reply #3 on: July 27, 2012, 09:27:19 pm »
Quote
right axis title is not shown
Did you set Title.Visible = true?

Quote
vertical line that would be cursor for graph and also show current values
Use TDataPointCrosshairTool. See "tools" demo for an example.
Alternatively, you can use TDataPointDragTool combined with TConstantLine --
see "line" demo for an example.

Quote
How can i get series value at cursor position from x,y on mouse move
Use ASender.Position property from within the TDataPointCrosshairTool. OnDraw
event handler to get a graph coordinates of the cursor.
Use Series and PointIndex properties to get the series point nearest to the cursor position.

#### wp

• Hero Member
• Posts: 7332
##### Re: TAChart Logarithmic and Linear scale on one Chart
« Reply #4 on: July 27, 2012, 11:22:54 pm »
Quote
to get a graph coordinates of the cursor.

Since you are new to TAChart and want to use logarithmic axes you maybe are not aware that the "graph coordinates" are numbers after calculating the logarithms. This mean you have to back-transform the position in order to get the value as displayed on the axis. From the OnDraw event handler of TDatapointCrosshairTool you can do this, for example, in the following way -- the result will be transferred to a label caption:

Code: [Select]
`procedure TForm1.ChartToolset1DatapointCrosshairTool1Draw(ASender:TDatapointCrosshairtool);var  series: TCustomChartSeries;  y: Double;begin  if not (ASender.Series) is TCustomChartSeries then    exit;  series := TCustomChartSeries(ASender.Series);  y := series.ParentChart.AxisList[series.AxisIndexY].GraphToAxisY(ASender.Position.Y);  Label1.Caption := Format('y = %g', [y]);end;`
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

#### markostarko

• New Member
• Posts: 10
##### Re: TAChart Logarithmic and Linear scale on one Chart
« Reply #5 on: July 28, 2012, 03:23:56 pm »
Thanx for all support, project is almost finished. Lazarus and i are definetly frends from now on.

#### markostarko

• New Member
• Posts: 10
##### Re: TAChart Logarithmic and Linear scale on one Chart
« Reply #6 on: July 28, 2012, 08:23:10 pm »
Just one more think, do i need new version of Lazarus get DatapointCrosshairTool,
as i saw from forum it's your contribution.
My question in short where to get the component.

#### wp

• Hero Member
• Posts: 7332
##### Re: TAChart Logarithmic and Linear scale on one Chart
« Reply #7 on: July 29, 2012, 12:17:31 am »
I would not recommend to merge this component into an existing installation. Get yourself a current Lazarus snapshot from http://freepascal.dfmk.hu/test/lazarus/ (this link is at the left-hand side of this forum). If you are on Windows, these versions are ready to install. And don't be scared by the message that "you are using completely untested software" - the snapshots are very stable. Delete (or rename) the old lazarus folder before installing the snapshot.
« Last Edit: July 29, 2012, 12:20:53 am by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...