Programming > LCL

[Solved] 2 Tchart same x range

(1/2) > >>

coimbras:
Hello.
I just searching in google, cant find solution...

Is there a way to put the maximum xx in a tchart is now display,in a variable, for use in a second tchart?

I haver two tchar in same window. But the values in the second are a little "shorter" than in the first.
My program reads from disk a table, and display it in a tchart. In other step the user reads other table from disk, and it display in the second chart.

in  the folowing code the maxgrafico1 and mingrafico1 return 0 in the showmessage.

Many thanks.



--- Code: Pascal  window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  for x := 0 to Length(Tabela1) - 1 do    Chart1LineSeries1.AddXY(strtofloat(Tabela1[x, 0]), strtofloat(Tabela1[x, 7]));   maxgrafico1:= Chart1.AxisList[1].Range.Max;  mingrafico1:= Chart1.AxisList[1].Range.Min;     ShowMessage( floattostr(mingrafico1) + ' ' + floattostr(maxgrafico1));

wp:
If I understand correctly you want to know the range of the axes in a chart. The most flexible way, I think, is to use the function LogicalExtent of the Chart. This returns a rectangle defined by corner points a and b - a is the bottom/left corner, b the top/right corner of the area covered by the data. There is also a CurrentExtent which is very similar but includes also the margins around the data areas (property Chart.Margin).  So, in otherwords

- Chart.LogicalExtent.a.x is the minimum x value of all series
- Chart.LogicalExtent.a.y is the minimum y value of all series
- Chart.LogicalExtent.b.x is the maximum x value of all series
- Chart.LogicalExtent.b.y is the maximum y value of all series.

- Chart.CurrentExtent.a.x is the minimum x value of all series minus the left chart margin (converted to "world" coordinates)
- etc.

You can also write to this property, and this way you force an axis to a specific limit. But the Extent is a record, and the chart does not provide a setter for the record elements; therefore you must set the entire Extent record using an intermediate variable. And note: Maximum must always be larger than Minimum!

Example

--- Code: Pascal  window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses  TAChartUtils; { TForm1 } procedure TForm1.Button1Click(Sender: TObject);var  ex: TDoubleRect;begin  ex := Chart2.LogicalExtent;  ex.b.y := Chart1.LogicalExtent.b.y;  Chart2.LogicalExtent := ex;end;

coimbras:
Well... This issue is problematic.

I have 2 procedures, first drwas chart1, second draws chart2.

In some "codes" i´ve tried if pass the LogicalExtend to double variables, they return -1 1 -1 1 ... :(
It works as i want in the following code:


--- Code: Pascal  window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  //Reads Values from Chart1 on the other procedure  //Minx:=ExtensaoGrafico1.a.x;                 //These 2 lines here return -1 1  //Maxx:=ExtensaoGrafico1.b.x;  if (Chart1.LogicalExtent.a.x>-10) and (Chart1.LogicalExtent.b.x<10) then             //Check if "exists" Chart1->Default    begin      ShowMessage('Aplicados valores xx do Gráfico 2');      Minx:=Chart2.LogicalExtent.a.x;      Maxx:=Chart2.LogicalExtent.b.x;    end  else    begin      Minx:=Chart1.LogicalExtent.a.x;      Maxx:=Chart1.LogicalExtent.b.x;    end;   //Miny:=Chart2.LogicalExtent.a.y;              //These 2 lines return -1 1  //Maxy:=Chart2.LogicalExtent.b.y;   ExtensaoGrafico2.a.x:= Minx;  ExtensaoGrafico2.a.y:= Chart2.LogicalExtent.a.y;  ExtensaoGrafico2.b.x:= Maxx;  ExtensaoGrafico2.b.y:= Chart2.LogicalExtent.b.y;  Chart2.LogicalExtent:= ExtensaoGrafico2;
For now it is enough ... i see that some posts have the [SOLVED] how i put it?

Thanks.

wp:
Can you strip down your project into a simple demo so that I can better understand and play with it? Pack .pas, .lfm, .lpr and .lpi file into a common zip and upload it under "Attachments and other options".

To mark an issue as "solved" edit the title of the first post (you always can edit your own posts).

coimbras:
This is the screen, still not working 100%...

Navigation

[0] Message Index

[#] Next page

Go to full version