Recent

Author Topic: backcolor subdivision  (Read 7234 times)

frederic

  • Full Member
  • ***
  • Posts: 226
backcolor subdivision
« on: March 22, 2016, 09:57:41 pm »
dear specialists

when one defines the backcolor of a chart the whole chart area is meant.

i wondered ,if it is possible to subdivide the canvas of the chart in different backcolors colors  in stead of one color

f.i.       0<x10 , 0<y<100: clyellow
           10<x <50,0<y<100 :clblue
          50<x<100,0<y<100: slsilver

frederic


wp

  • Hero Member
  • *****
  • Posts: 11916
Re: backcolor subdivision
« Reply #1 on: March 22, 2016, 11:34:32 pm »
Add a TChartStyles component, select the component, in the object inspector click at the "..." next to "styles", add two styles, set their color by using their brush. Then assign the TChartStyles to the Strips of the BottomAxis.Marks. See attached demo.

If you want irregular intervals you have to add (another) axis to which you assign the styles.

frederic

  • Full Member
  • ***
  • Posts: 226
Re: backcolor subdivision
« Reply #2 on: March 23, 2016, 12:24:53 pm »
wp,

i tried with the styles property , but it is meant for a repetitive performance.

i tried to make it simple
target:
on a bottomscale of 0 to 200  i want to able to have the area  0-150 in clblue and beyond to 200 in clyellow
the xvalue of 150 must be adjustable
 
when i fill  with styles1 (chartstyle1=clbleu and chartsstyle2 =yellow) :repeatcount = 150  then the whole area turns bleu  instaed of what i would expect 150-200 in yellow


how i should use a second bottomaxis is not clear to me

frederic

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: backcolor subdivision
« Reply #3 on: March 23, 2016, 03:56:58 pm »
See attached project.

Yes, the TChartStyles are mean for repetitive action. So, you must prevent it to become repetitive, you must cover the entire axis space by stripes, they only repeat themselves if any axis extent it left.

Add a TListChartSource, it will define the points where the color changes. In your example, it is only one, 150. Add code to write this number into the listchartsource, only this more, no more!

Then add a second x axis (ObjectTree, right-click "AxisList" --> "Add item"). Select the new axis, it is a y axis by default, but by setting "Alignment" to alBottom it becomes an x axis. Select both x axes, set their "Group" to any non-zero number (e.g. 1), this causes both x axes to be drawn on the same line. Select Marks of the new x axis, hide the labels by setting "Visible" = false. Set "Source" to the ListChartSource added above. Set "Stripes" to the TChartStyles. You need two stripes, the first one blue, the second one yellow. The first stripe reaches from "neg inifinity" up to the point defined in the list chource, the second one from this point up to "pos infinity".

frederic

  • Full Member
  • ***
  • Posts: 226
Re: backcolor subdivision
« Reply #4 on: March 23, 2016, 04:51:15 pm »
wp,
 interesting ,that gives me a kick in the right direction
never thought of using a separate listchartsource  for that .

that gives indeed great flexibilty better than in delphi

thanks

frederic

  • Full Member
  • ***
  • Posts: 226
Re: backcolor subdivision
« Reply #5 on: March 24, 2016, 11:51:38 am »
wp

i need to set the colors of the stripes by code .

how do you do that?

thanks for the hint ,in advance
frederic

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: backcolor subdivision
« Reply #6 on: March 24, 2016, 12:04:58 pm »
Code: Pascal  [Select][+][-]
  1.   ChartStyles1.Styles[0].Brush.Color := Color1;
  2.   ChartStyles1.Styles[1].Brush.Color := Color2;
  3.   Chart1.Invalidate;

frederic

  • Full Member
  • ***
  • Posts: 226
Re: backcolor subdivision
« Reply #7 on: March 31, 2016, 10:48:38 am »
little question

when i want to delete an object from the chart i click on the icon on the chart and delete.
when i do this with the chartstyles icon ,i get acces violation

why is that?

frederic

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: backcolor subdivision
« Reply #8 on: March 31, 2016, 11:40:06 am »
Seems to be a bug. Let me see...

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: backcolor subdivision
« Reply #9 on: March 31, 2016, 12:03:29 pm »
Should be fixed in r52090. Please test and report back.

If you don't use Lazarus trunk you can probably apply this temporary patch manually to older versions:
  • Go to folder (lazarus)/components/tachart
  • Make a backup copy of TAGraph.pas
  • Open TAGraph.pas in Lazarus or any other editor
  • Find the "uses" line after "implementation", add "TAStyles"
  • Find the procedure "TChart.Notification", replace it by the following code. Then rebuild the IDE.
Code: Pascal  [Select][+][-]
  1. procedure TChart.Notification(AComponent: TComponent; AOperation: TOperation);
  2. var
  3.   ax: TChartAxis;
  4. begin
  5.   if (AOperation = opRemove) and (AComponent = Toolset) then
  6.     FToolset := nil
  7.   else if (AOperation = opRemove) and (AComponent = GUIConnector) then
  8.     GUIConnector := nil
  9.   else if (AOperation = opRemove) and (AComponent is TChartStyles) then begin  // <-- added from here ...
  10.     for ax in FAxisList do
  11.       if ax.Marks.Stripes = AComponent then
  12.         ax.Marks.Stripes := nil;
  13.   end;                                                                         // <-- ... to here
  14.  
  15.   inherited Notification(AComponent, AOperation);
  16. end;

frederic

  • Full Member
  • ***
  • Posts: 226
Re: backcolor subdivision
« Reply #10 on: March 31, 2016, 01:20:50 pm »
i use now 1.6 svn 51630    2016-2-14;
i will update my version first

frederic

frederic

  • Full Member
  • ***
  • Posts: 226
Re: backcolor subdivision
« Reply #11 on: March 31, 2016, 02:41:16 pm »
i used the latest official lazarus release,

i changed the code in the notification procedure and ran your project from above,
i got an error that the class tastyles was missing before i even deleted it.

i may have done something else wronge due to my unexperience , ( i never changed lazarus code before ,one bridge to far). so i leave  this item here

frederic


wp

  • Hero Member
  • *****
  • Posts: 11916
Re: backcolor subdivision
« Reply #12 on: March 31, 2016, 05:36:39 pm »
Before you compile any chart project you MUST rebuild the IDE because you want to delete the ChartStyles in designmode, and the new code must be contained in the IDE. The easiest way to recompile Lazarus is to open the menu "Tools" and select "Build Lazarus with profile...". The compilation process takes some time, be patient. At the end Lazarus closes and restarts automatically with the new IDE. Then you can begin with a new project, add a TChart and TChartStyles, and link the ChartStyles to the Marks.Stripes of one of the axes. If you now delete the TChartStyles from the IDE it must not crash any more.

If the compilation of Lazarus fails or the newly started Lazarus hangs you have a backup of the old lazarus.exe named as lazarus.old.exe - rename it to lazarus.exe and your can use the old Lazarus again.

I tested the patching and recompilation procedure with a new installation of Laz 1.6 - it works, for sure.

frederic

  • Full Member
  • ***
  • Posts: 226
Re: backcolor subdivision
« Reply #13 on: March 31, 2016, 09:22:59 pm »
oke , wp ,  it works

frederic

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: backcolor subdivision
« Reply #14 on: March 31, 2016, 09:33:45 pm »
I put it onto the merge list for Lazarus 1.6.2. So, when the new version will be released and you update you will have the fix included.

 

TinyPortal © 2005-2018