[SOLVED] Adding areas with a line problem lazarus / 55-TAChart ---------------------------------------------------------------------- donnie · 2016-04-07 10:16 Hi there, I have a problem adding an area to a tachart. I have a TAChart which I always draw a line. I want to add 3 areas in order to show some limits of this line. For example the first area is from -5 to 5, the second is from -3 to 3 and the third is from -2 to 2. The line is drawn first (by default). I add the first area(-5,5) and everything is ok. I add the second(-3,3) and no problem again. The line is in front, after that the first area and after that the second area. When I am going to add the third area I have a problem. The third area is drawn in front of all and an area is missing. These areas are called all together by a routine which draws first,second,third area with that order. As I have set properties for all these areas in order to draw them whenever I want, the problem is not with the third area as code. For example if I don't choose to draw the first and I draw the second and the third area everything is ok. If I add the first, I have the same problem again. If I don't choose to draw the second and I draw the first and the third area everything is ok. If I add the second and have the same problem again. Do you know except from the Chart.AddSeries(myarea) should I do something else? Does a tachart accepts only 2 areas? Should I somehow increase the number of area series? How can I also bring in front a selected serie? As I can see know the first serie that is drawn is the first visible serie in my chart. Or not? Thank you... I just noticed that when I have many lines to draw in these three areas it works fine. With one line and three areas is the problem. Every Serie I draw has serie.zposition := 0; which means that is first in my list to de drawn. I have the same routine with many lines and works fine. The same routine with one line it draws them oposite. I change the order and then one area is missing. Very confused... ---------------------------------------------------------------------- wp · 2016-04-07 15:26 "Add an area to a chart" - does this mean: you want to add an area series? "A chart in which I always draw a line" - does this mean: you always have a lineseries in the chart. And is you problem that some series are not visible because they are covered by a "larger" area series in front of them? You can use the property ZPosition to control the drawing order. The default value 0 means: draw the series in the order they were added to the chart. If you given them a non-zero value for ZPosition you know that the one with the lowest ZPosition is drawn first, etc. The one with the highest ZPosition is drawn last - it must be the series with the smallest y values otherwise it will cover the other series. Additionally, you can experiment with the Transparency of the series which makes even area series translucent, and you can see what is behind them. ---------------------------------------------------------------------- donnie · 2016-04-08 08:15 Yes, lineseries and areaseries(sorry for the mistake). I have found the zposition property. But when you add many areas with many lines the zposition makes no sense. I have attached an example in which I add three areaseries and three lineseries. The lineseries are in comment. Run the example and press the button1 to see how the areaseries are added. This is how I need them. But when I add a line(first or last at the list af add series-see comments on code) things are confused. Remove the comments from line1(first or last) and run it. Now remove the comments from line2 and run it. Now for line 3. The result I want is the lineseries to be in front of areaseries and the order of areaseries to be as it was with no lines(green,blue,red). When a line is added the zposition changes for all series somehow. ---------------------------------------------------------------------- wp · 2016-04-08 08:36 When trying to download your demo I am getting "not allowed to access this section". Since I don't have issues accessing zip attachments of other post I guess its the rar format which causes trouble. Please save your project as zip or 7z and upload again. If you want to have the line series in front of all the area series make its zPosition larger than that of the area series. If there are several area series in the chart you must analyze the data values. The area series with the highest data values must have the lowest zPosition, the one with the lowest data values must have the highest zPosition (but still smaller than the zPosition of the lineseries). But of course, there are intermediate cases, and therefore, I would not recommend to have more than 1 area series in the same chart because there is always a chance that one series will cover parts of the other. The only solution is to select some intermediate value for the areaseries Transparency, say 50. Did you try that? But this will get ugly as will if you have "many areas". [EDIT] No, the download of the rar was successful now. ---------------------------------------------------------------------- donnie · 2016-04-08 08:57 This is the zip file ---------------------------------------------------------------------- wp · 2016-04-08 09:20 I see now. You are using area series in order to get a striped background for the line series. A better way to achieve this is using TChartStyles and the Stripes property of the y axis. There was a recent discussion of this topic which I don't want to repeat at the moment, please see http://forum.lazarus.freepascal.org/index.php/topic,32040.0.html In case you insist on your solution use the ZPositions like in the code below: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var  thirdlimit, secondlimit, firstlimit: TAreaSeries;  line1, line2, line3: TLineSeries;begin  Chart1.ClearSeries;  line1 := TLineSeries.Create(self);  line2 := TLineSeries.Create(self);  line3 := TLineSeries.Create(self);  firstlimit := TAreaSeries.Create(self);          // -1 ... +1  secondlimit := TAreaSeries.Create(self);         // -3 ... +3  thirdlimit := TAreaSeries.Create(self);          // -5 ... +5   Chart1.AddSeries(line1);  Chart1.AddSeries(firstlimit);  Chart1.AddSeries(secondlimit);  Chart1.AddSeries(thirdlimit);  Chart1.AddSeries(line2);  Chart1.AddSeries(line3);   firstlimit.AddXY(1, 1);  firstlimit.AddXY(10, 1);  firstlimit.AddXY(10, -1);  firstlimit.AddXY(1, -1);  firstlimit.SeriesColor := clgreen;  firstlimit.Transparency:=65;  firstlimit.UseZeroLevel:= true;  firstlimit.ZPosition := 100;  // Use some intermediate value to start with   secondlimit.AddXY(1, 3);  secondlimit.AddXY(10, 3);  secondlimit.AddXY(10, -3);  secondlimit.AddXY(1, -3);  secondlimit.SeriesColor := clBlue;  secondlimit.Transparency:=75;  secondlimit.UseZeroLevel:= true;  secondlimit.ZPosition := 99;  // Must be underneatch firstlimit --> use ZPosition smaller than that of firstlimit   thirdlimit.AddXY(1, 5);  thirdlimit.AddXY(10, 5);  thirdlimit.AddXY(10, -5);  thirdlimit.AddXY(1, -5);  thirdlimit.SeriesColor := clRed;  thirdlimit.Transparency:=85;  thirdlimit.UseZeroLevel:= true;  thirdlimit.ZPosition := 98;  // must be underneath firstlimit and secondslimit --> use even smaller ZPosition   line1.AddXY(1, -5);  line1.AddXY(10, 5);  line1.SeriesColor := clYellow;  line1.ZPosition := 1000;  // Must be above all area series --> user ZPosition larger than that of firstlimit   line2.AddXY(1,0);  line2.AddXY(10,0);  line2.SeriesColor:= clLime;  line2.ZPosition := 1001;  // or use same ZPosition as line1   line3.AddXY(1,5);  line3.AddXY(10,-5);  line3.SeriesColor:= clMaroon;  line3.ZPosition := 1002;  // or use same ZPosition as line1 or line2 end;Since the areaseries are well- ordered in this example  it is not required to use the Transparency any more. ---------------------------------------------------------------------- donnie · 2016-04-08 09:56 simply the best man... ---------------------------------------------------------------------- wp · 2016-04-08 10:07 And since the area series is drawn starting from the ZeroLevel (if UseZeroLevel) you can simplify your code like this (shown for "firstlimit" only): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   firstlimit.AddXY(1, 1);  firstlimit.AddXY(10, 1);  //firstlimit.AddXY(10, -1);      <-- remove  //firstlimit.AddXY(1, -1);       <-- remove  firstlimit.ZeroLevel := -1;   // <-- add  firstlimit.SeriesColor := clgreen;  firstlimit.UseZeroLevel:= true;  firstlimit.ZPosition := 100; ---------------------------------------------------------------------- donnie · 2016-04-08 11:19 Thank you very much!!!