proper Yaxis design with panes lazarus / 55-TAChart ---------------------------------------------------------------------- frederic · 2015-03-13 11:22 dear specialists after having discussed a proper x-axis design extensively , I encountered several issues when dealing with the Y axis where i would like to hear your opinion on. 1. in the code from the "proper X-axis" thread we  are able to zoom the x-axis.When zooming we only look at a part of our chart  which could be easily only fill the upper 10 % of the chart area.Not optimal. I can code of course an automatic scaling that the total area of the relavant  pane will be filled by deriving the min y and max y values between a.x and b.x of the current extent. I wondered if there is already a build in facility to cover this job.A kind of yzooming per pane. 2. it was suggested in the "proper X-axis" thread  to use horizontal constantlines as separation lines between the  panes.I wondered if these lines can be used as splitter lines which you can grab. inorder to change the panes division in the y-direction. 3. i have several horizontal lines within a panes but i am not able to give it a proper y-axis value when i use constant lines so i am using the lineseries in stead . Is that the proper way? frederic ---------------------------------------------------------------------- wp · 2015-03-13 12:06 (1) & (2): I think both questions are solved if you use two separate charts (instead of panes) put into a common panel,  one chart top- aligned, the other one client-aligned, and a splitter in between. Turn off the x labels of the upper chart such that both charts touch. Link the axes by adding a TChartExtentLink component and adding both charts to its LinkedCharts list. Finally, to keep the y axis at the same distance to the left border, set the LabelSize property of both left axes to the same value which must be large enough to avoid overlapping of the labels into the axis title - this is a manual adjustment. (3) This was the "just to confuse you" in the last posting... A constant line series is ok. You probably did not specify the YAxisIndex of the series. If you don't do that then the series does not know about the transformation of the y axis (autoscale to get the pane effect) and the series is plotted according to the invisible axis. ---------------------------------------------------------------------- frederic · 2015-03-13 15:23 wp ad1 and 2 . That is what i had before. The disadvantage there is when i had 4 charts on top of each other that a lot of space is being consumed by the labels of the x-axis . So what  i did there ,i removed the 'in between'  X-axis labels (the ones in the former thread). The disdvantage then was that extent of the axises( the lowest chart compared to the others)   became different . But coming back to my question 1 on this. When we fill the chart with data and display the chart  with all the data then there is proper Y-axis for for that situation.So there is a internal procedure which determines ymin and ymax of the data range to get a proper display.And this procedure couldbe used for a zoomed extent. Ad3  I couldn't find an YAxisIndex  only XAxisIndex  . frederic ---------------------------------------------------------------------- wp · 2015-03-13 16:12 QuoteThe disdvantage then was that extent of the axises( the lowest chart compared to the others)  became different.That is the reason why I proposed to add a TChartAxisLink. It makes sure that whenever you zoom into the upper chart, the lower chart will follow (use Mode=elmOnlyX to link only the x axes). QuoteWhen we fill the chart with data and display the chart  with all the data then there is proper Y-axis for for that situation.So there is a internal procedure which determines ymin and ymax of the data range to get a proper display.And this procedure couldbe used for a zoomed extent.I think I do not understand what you mean here. I thought you want to zoom the upper pane but keep the ratio of panes constant? QuoteAd3  I couldn't find an YAxisIndex  only XAxisIndexSorry - the series properties linking them to an axis are  called AxisIndexX and AxisIndexY ---------------------------------------------------------------------- frederic · 2015-03-13 16:43 wp QuoteThat is the reason why I proposed to add a TChartAxisLinkall these charts were linked with TChartAxisLink and elmonlyX  but in the meantime I have my partially autoscaled pane in the way as described above here for the pan-mousewheeldown  operation: Code: [Select]procedure TForm1.PanMouseWheelToolAfterMouseWheelDown(ATool: TChartTool;   APoint: TPoint); var DTmin,dtmax,ylaag,yhoog:double;      extent: TDoubleRect;     X0,xtot:double;     n:integer; begin  extent := Chart1.CurrentExtent;  xtot:= extent.b.x;  X0:=  extent.a.x;   Fnscreenstart:= ConvertDaysPassedtoLineNumber(x0);   Fnscreenend := ConvertDaysPassedtoLineNumber( xtot);   FnYscreenmin:=Fclose[Fnscreenstart];   FnYscreenmax:=Fclose[Fnscreenstart];   for n:= Fnscreenstart to Fnscreenend do   begin        if Fclose[n]> FnYscreenmax then FnYscreenmax:= Fclose[n];//<--- value to be scaled        if Fclose[n]< FnYscreenmin then FnYscreenmin:= Fclose[n];   end;    UpdateAxisLabels;   chart1.axislist[4].marks.range.max:=  FnYscreenmax;   chart1.axislist[4].marks.range.min:=  FnYscreenmin;   chart1.axislist[4].marks.range.usemax:=  true;   chart1.axislist[4].marks.range.usemin:=  true;    chart1.axislist[4].range.max:=  FnYscreenmax;   chart1.axislist[4].range.min:=  FnYscreenmin;   chart1.axislist[4].range.usemax:=  true;   chart1.axislist[4].range.usemin:=  true;  ZoomHistory.Add(Chart1.PrevLogicalExtent); end;                  The same addition for zoomX MWup,zoomXMWdown and pan MWup. QuoteSorry - the series properties linking them to an axis are  called AxisIndexX and AxisIndexY i saw that although i have only the property AxisIndexX in the property list of a constantline i can connect to  a leftaxis  ;so that is solved now. QuoteI think I do not understand what you mean here. I thought you want to zoom the upper pane but keep the ratio of panes constant? You are right. frederic ---------------------------------------------------------------------- wp · 2015-03-17 10:18 Quote from: fredericThe disdvantage then was that extent of the axises( the lowest chart compared to the others)   became differentDid you freeze the position of the left axes by means of the same non-zero "LabelSize" of the y axis? Quote from: fredericI wondered if these lines can be used as splitter lines which you can grab. inorder to change the panes division in the y-direction.Add a DataPointDragTool to the ChartTools. Assign ssLeft to its "Shift" property. Move this tool to the top of the tool stack, it must be the first one to catch the left mouse move. Assign the series index of the ConstantLine to the "AffectedSeries" of the Dragtool (otherwise you will drag datapoint from the other series as well which you probably will not want to). Write code in the AfterMouseMove event of the DragTool which links the MaxValue of the lower pane and the Minvalue of the upper pane to the "Position" of the constant line. Look at my example above: In this project there are two AutoScaleAxisTransforms. In the one for the lower pane, the y axis ranges between 0 and 2, in the one of the upper pane y is between 4 and 6 - these numbers are given in invisible "graph" units, not the "axis" units displayed along the axis and correspond to the MinValue and Maxvalue parameters of the AutoScaelAxisTransform. In my example, the constant line did not have an axis assignment in XAxisIndex, therefore, the "Position" value does not run through the Axistransformation and is specified in graph units to be 4. When you drag the constant line you change its "Position" which is the same the lower end of the upper pane. This code should basically do what you want (there is one issue left: the chart forgets about the old zoomed rectangle - I don't have a solution at the moment): Code: [Select]procedure TForm1.DataPointDragToolAfterMouseMove(ATool: TChartTool;   APoint: TPoint); var   p: Double; begin   if TDataPointDragTool(ATool).Series <> nil then begin     p := TConstantLine(TDataPointDragTool(ATool).Series).Position;     // Make sure to retain a minimum height of each pane:     if p < 2.5 then p := 2.5;  // if < 2 then the height of the lower pane would become negative     if p > 5.5 then p := 5.5;  // if > 6 then the height of the upper pane would become negative     ChartAxisTransformations1AutoScaleAxisTransForm1.MaxValue := p-2;  // there is a gap of 2 units between upper and lower pane     ChartAxisTransformations2AutoScaleAxisTransform1.MinValue := p;     TConstantLine(TDataPointDragTool(ATool).Series).Position := p;   end; end; ---------------------------------------------------------------------- frederic · 2015-03-17 13:51 wp QuoteDid you freeze the position of the left axes by means of the same non-zero "LabelSize" of the y axis? all 4 visible leftaxis  property  settings were the same .i spend numerous hours to be sure of that (in attachment a copy).It has been already some time ago when i was wrestling with it and finally gave up. thanks wp for  the tip on the DataPointDragTool drag tool for moving pane  separation lines; i am going to experiment with it frederic ---------------------------------------------------------------------- wp · 2015-03-17 13:56 Not sure if you wrote your Lazarus version somewhere, but it seems that your version does not yet support the LabelSize property. You'll need trunk or 1.4 (RC1/2). ---------------------------------------------------------------------- frederic · 2015-03-17 14:45 wp version see attachment, i thought this was the most recent one i am on windows vista and i am not familiar with lazarus "trunk ?"  i looked at the sourge forge site and couldn't find it . where can i download that version? frederic ---------------------------------------------------------------------- wp · 2015-03-17 14:49 Yes, most recent stable one. But the LabelSize was introduced later, and therefore is in the trunk version and - since the new version is currently being tested before release - in the release candidates of v1.4. ---------------------------------------------------------------------- frederic · 2015-03-17 15:03 wp my modification crossed your answer . but  i will wait for the official release  . It is good to know that there is room for improvement there frederic ---------------------------------------------------------------------- frederic · 2015-03-17 20:58 wp Quote Assign the series index of the ConstantLine to the "AffectedSeries" of the Dragtool i have no experience with assigning  affected series; how do you do that ?. in attachment a copy of my object inspector with the series. the 2 lines involved are chartseparation1 and chartsepartion2, but there names are not accepted and saved frederic ---------------------------------------------------------------------- wp · 2015-03-17 21:51 Above the object inspector, in the object tree, you see the series as children of the chart. The first one, Xaxisseries, has index 0 (not show, but just count), the second one, stoch1, has index 1, etc. chartseparation1 and chartseparation2 have index 3 and 4, respectively. You have to type these numbers into the "AffectedSeries" field; use a comma as separator, i.e. the "AffectedSeries" should be "3,4". Or, if you want the DataPointDragTool only to work on the "chartseparator1" series (index 3), the "AffectedSeries" should simply be "3" (of course without quotes). ---------------------------------------------------------------------- frederic · 2015-03-18 15:30 wp i implemented your method (movable paneseparation lines) in my test project in the attachments you see the printscreen results attach1: before grapping the middle separation line attach2: situation direct after having moved up the middle separation line.Although the distancemode was set “cdmOnlyY” we see that during moving up the X-axis zoomed out. Attach3: once touching the mouse in order to zoomX    we see a normal  screen situation again The crosshair', however, didnt function anymore . Because the crosshair is of more importance to me ,I tried a more simple approach by introduction of 2 buttons: Code: [Select]procedure TForm1.pane2_bigClick(Sender: TObject); begin      ChartAxisTransformations2AutoScaleAxisTransform1.MaxValue:=55;      ChartAxisTransformations3AutoScaleAxisTransform1.minValue:=60;     separationline2.position:=58; end; procedure TForm1.Pane2_smallClick(Sender: TObject); begin      ChartAxisTransformations2AutoScaleAxisTransform1.MaxValue:=35;       ChartAxisTransformations3AutoScaleAxisTransform1.minValue:=40;       separationline2.position:=35; end;  that gave the same results and the operation of the crosshair was not affected; frederic ---------------------------------------------------------------------- wp · 2015-03-18 17:58 I had written about the zooming issue above, but don't have a solution at the moment. What is wrong with the crosshair? ---------------------------------------------------------------------- wp · 2015-03-18 22:19 Now I looked into the TAChart code and saw that the chart zooms to full extent due to extent changes caused by transformations. There is a comment in this procedure indicating that there is good reason for this, and therefore, I don't want to change this behavior within TAChart. But there is another solution: In the MouseMove handler of the DatapointDragTool store the current extent in a local variable, change the parameters of the AutoScaleAxisTransform, and then restore the LogicalExtent of the chart. Call Chart.Prepare before because this recalculates  a variety of internal variables. This is my code, it replaces the one in my posting of March 17, 2015, 11:18:30: Code: [Select]procedure TForm1.DataPointDragToolAfterMouseMove(ATool: TChartTool;   APoint: TPoint); var   p: Double;   ex: TDoubleRect; begin   if TDataPointDragTool(ATool).Series <> nil then begin     p := TConstantLine(TDataPointDragTool(ATool).Series).Position;     if p < 1 then p := 2.5;     if p > 5 then p := 5.4;     ex := Chart1.LogicalExtent;                                      // save current logical extent     ChartAxisTransformations1AutoScaleAxisTransForm1.MaxValue := p-2;  // --> chart unzooms here     ChartAxisTransformations2AutoScaleAxisTransform1.MinValue := p;  // ... and here as well     TConstantLine(TDataPointDragTool(ATool).Series).Position := p;     Chart1.Prepare;                                                  // recalculate internal variables     Chart1.LogicalExtent := ex;                                      // restore logical extent   end; end; ---------------------------------------------------------------------- frederic · 2015-03-19 08:47 wp the crosshair was not visible and at some stage produced even an SIGSEGV -error . I try to reproduce the error this morning and discovered a wrong reference with.....affectedseries in the crosshairtool. I had played around with lineseries and had also deleted series yesterday; I suspect that that was the reason because when with the right reference the crosshair was back again frederic ---------------------------------------------------------------------- frederic · 2015-03-22 16:40 wp Sometimes i cannot understand what happens with the Y-axis presentation. In my application i introduced the panes as is discussed above I get however no y-axis marks  at all although during construction they were there. Therefore i try to simulate this step by step  with the code project above attach1 gives a printscreen in or former project             note that there is no yaxis  for the lowest chart            the red line is the lineseries belonging to this chart which is used to provide the labels for the         bottomaxis for the 3 panes attach2 and 3 are print screens of the object inspector of leftaxis of the lowest pane. Q1:  What could this be here ?. Q2 : the panes in my application have the same setup so what else coulld be he reason ? frederic ---------------------------------------------------------------------- wp · 2015-03-22 17:11 There are many reasons why axes don't get labels, it is hard to tell from the distance what's wrong... I think you have to pack your charting code into a separate project which shows the issue and which you can upload here. I must be able to run the project myself and see all your settings. I can't remember if I already told you: pack all pas, lfm, lpi and lpr file into a single zip, include the data file (or use code-generated data in the demo), no ppu, exe. ---------------------------------------------------------------------- frederic · 2015-03-23 09:30 wp attached you will find testproject and a testfile datafile (i hope it is not too big) frederic ---------------------------------------------------------------------- wp · 2015-03-23 16:12 In the attachment there's a corrected version in which the labels of the lower panel appear and in which the draggable separator lines work. The axis labels appeared after I turned off the Marks.AtDataOnly of this axis. This is strange. It is strange also that the labels of the upper pane reach into the center panel. When I have time I'll have to look into TAChart to understand this, probably there's a bug. With the draggable separator lines I centralized your code into single methods, "SetUpperSeparatorLine" and "SetLowerSeparatorLine"; this makes sure that always the same numbers are used for the invisible y axis (you sometimes had a gap between the panes of 2, sometimes 5 units). How to hold the height of the center pane constant was not coded correctly. In the data reading method I used the system's formatsettings to better control readability of the file. In my system, the date separator is a point, in the file it is a dash. Using the format settings you can read dates on systems with different date separator (the same with the decimal separator). I did not look into the x axis which looks wrong, but maybe you've solved this already since we had discussed the issues before. ---------------------------------------------------------------------- frederic · 2015-03-23 16:23 wp i just had prepared a reply in which the "marks.ATDataOnly "was changed;You answered my question about it. i am going to look at the changes you made we keep learning .  thanks again frederic ---------------------------------------------------------------------- frederic · 2015-03-24 10:01 wp Quotehe axis labels appeared after I turned off the Marks.AtDataOnly of this axis. This is strange. It is strange also that the labels of the upper pane reach into the center panel. When I have time I'll have to look into TAChart to understand this, probably there's a bug what i found strange that when once you have connected the several left yaxis to the different transformations ,I would expect that, when you look at the left axis property of the chart, there will be no reference made or to all three.But what you see there is that the reference is made to only to transformation1. Is this cosmetic so that this property has no meaning in case of panes or will it affect the settings? frederic ---------------------------------------------------------------------- wp · 2015-03-24 10:39 Quotewhen you look at the left axis property of the chart, there will be no reference made or to all three.But what you see there is that the reference is made to only to transformation1Which kind of reference do you mean? The first left axis (index 0) is linked to ChartAxisTransformation1, the second left axis (index 2) is linked to ChartAxisTransformation2, and the third left axis (index 3) is linked to ChartAxisTransformations3. The series in the lower pane ("stoch1") uses left axis #0 (i.e. is subject to ChartAxisTransformations1; the series in the center pane ("stoch 2") uses left axis #2 (--> ChartAxisTransformation2), and the series in the upper pane ("indexseries") uses left axis #3 (--> ChartAxisTransformation3). I just checked it - that's how it should be. I just uploaded to svn a TAChart version in which axis labels do not reach beyond each pane. It is not yet complete because I also want to fix title centering and add a feature which does not draw the axis line beyond the pane extent. ---------------------------------------------------------------------- frederic · 2015-03-24 12:47 wp QuoteWhich kind of reference do you mean? I may not express myself clearly in IT jargon.My excuse for that. But i meant ,when you click on chart1 in the component tree, the object inspector shows then the properties. Leftaxis is one of them and there you see  only 'charttransformations1'. Whilst, in our case ,we have a subdivision of the left axis ,each with its own charttransformation so  the leftaxis.transformationproperty at that particular place  should be made out of serve because it should be overruled by the pane-left-axis-settings frederic ---------------------------------------------------------------------- wp · 2015-03-24 15:25 Chart.LeftAxis is just for convenience, it refers to the first axis found having Alignment = calLeft - this is oversimplified for the case of paned charts. In the object tree, however, you see also the AxisList property of the chart. This lists all the axes. We have 3 left axes, the default one with index 0 plus two more with index 2 and 3. If you click at each of them you can check that different transformations are assigned to them. ---------------------------------------------------------------------- wp · 2015-03-26 17:08 My recent updates to trunk fix all (?) issues with paned charts. The modifications will be contained in version 1.4. There is also a new demo (lazarus/componens/tachart/demo/panes-2) which allows to play with pane parameters, and which demonstrates changing of pane size at run-time by dragging a "splitter" line with the mouse. ---------------------------------------------------------------------- frederic · 2015-03-30 13:54 wp may be solved in the coming release but anyway in above code i showed a method to automatic y-axisscaling of one of panes. In the testprojects it worked fine ;again after transferring it to my application it worked with panning but not with zooming whilst it did here in the test project. The code in the procedure  PanMouseWheelToolAfterMouseWheelDown(and ..up)  is the same as with the ZoomMouseWheelToolAfterMouseWheelDown(and..up) I looked of course at the differences but couldn't discover any. any idea what that could be frederic ---------------------------------------------------------------------- wp · 2015-03-30 14:25 Please post your current code, there's a lot of changes and I don't know if the one that I have is up-to-date. ---------------------------------------------------------------------- frederic · 2015-03-30 14:43 wp Code: [Select]procedure TForm1.ZoomMouseWheelToolAfterMouseWheelDown(   ATool: TChartTool; APoint: TPoint); var DTmin,dtmax,ylaag,yhoog:double;      extent: TDoubleRect;     X0,xtot:double;     n:integer; begin  extent := Chart1.CurrentExtent;  xtot:= extent.b.x;  X0:=  extent.a.x;  edit3.text:=floattostr(X0);  edit4.text:=floattostr(Xtot);   Fnscreenstart:= ConvertDaysPassedtoBARNumber(x0);   Fnscreenend := ConvertDaysPassedtoBARNumber( xtot);  if    grafiekdatageladen then   begin   FnYscreenmin:=Fclose[Fnscreenstart];   FnYscreenmax:=Fclose[Fnscreenstart];   for n:= Fnscreenstart to Fnscreenend do   begin          if ((n>0) and (n <  NUM_LINES)) then        begin             if Fclose[n]> FnYscreenmax then FnYscreenmax:= Fclose[n];             if Fclose[n]< FnYscreenmin then FnYscreenmin:= Fclose[n];        end ;   end;  end;    UpdateAxisLabels;   if    grafiekdatageladen then   begin   chart1.axislist[4].marks.range.max:=  FnYscreenmax;   chart1.axislist[4].marks.range.min:=  FnYscreenmin;   chart1.axislist[4].marks.range.usemax:=  true;   chart1.axislist[4].marks.range.usemin:=  true;   chart1.axislist[4].range.max:=  FnYscreenmax;   chart1.axislist[4].range.min:=  FnYscreenmin;   chart1.axislist[4].range.usemax:=  true;   chart1.axislist[4].range.usemin:=  true;  end;   yhoog:=  chart1.YImageToGraph(0);  DTmin:=  chart1.XImageToGraph(0);  //if  xzoomer then  ylaag:=  chart1.YImageToGraph(0);  DTmin:=  chart1.XImageToGraph(0);  edit1.text:=floattostr(DTmin);  edit2.text:=floattostr(Ylaag);   ZoomHistory.Add(Chart1.PrevLogicalExtent); end;                                     frederic ---------------------------------------------------------------------- wp · 2015-03-30 14:56 And the rest? The bug can be somewhere else. Please post a complete compilable project which shows the error (you can skip the data file this time). How is it supposed to work? Use the mouse wheel, ok. But which pane is supposed to zoom? Horizontally, or vertically, or both, or according to the selection in the combobox? ---------------------------------------------------------------------- frederic · 2015-03-30 15:33 wp , you misunderstood me in the projects i send to this forum it worked.(btw it is leftaxis3 which axis have to be automatically scaled as succesfully done there). The code and settings of the forums testproject where transferred to my application with the only difference of having other series in my own application however the described failure came up but i could not find other differences with test project where  it worked. Therefore a more general question where to look for in such a situation frederic ---------------------------------------------------------------------- wp · 2015-03-30 15:45 Sorry then I cannot help you. You have an example which is working, therefore you know that your task can principally be fulfilled with TAChart. If your main application is not working then the bug must be in there. Compare procedure by procedure, look at all object inspector settings. If you don't find any difference, backup the project into a new folder, erase the chart and redo it again step by step, thinking carefully about what you are doing. ---------------------------------------------------------------------- frederic · 2015-03-30 18:43 wp thanks for the advice . i keep searching frederic