### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: Chart Bounds & Legend Colour  (Read 762 times)

#### sdawilson

• New Member
• Posts: 14
##### Chart Bounds & Legend Colour
« on: May 27, 2024, 12:05:26 am »
Hi all,

...and thank you for the support. I think I'm nearly there with my simple plotting app.

I'm struggling with two final issues, as illustrated in the attachment.

The first is an unwanted area added to chart. I've set the axis ranges, the extents, and every other setting I can find, but it still adds a zone to the chart above the Y and X axis maxes.

The second is that I can't get the XY point colour to be the shown in the legend.

Any thoughts? Thank you for your help.

#### sdawilson

• New Member
• Posts: 14
##### Re: Chart Bounds & Legend Colour
« Reply #1 on: May 27, 2024, 12:10:28 am »
Apologies, the previously attached jpeg was a bit bit! Here is is smaller...

#### wp

• Hero Member
• Posts: 12072
##### Re: Chart Bounds & Legend Colour
« Reply #2 on: May 27, 2024, 12:48:38 am »
There must be some data points in your chartsource which make the chart axis scale itself to a value > 100. Please show code how you put the data into the series.

The legend can display several types of data depending on the Legend.Multiplicity property of the series:
- lmSingle: a single entry for each series, determined by the Title of the series
- lmPoint: each data point has a legend entry showing the data value and its symbol in the corresponding color - so I think, this is what you need.
- lmStyle: needed for example for stacked bar or area series, I think this is not relevant at the moment.

#### sdawilson

• New Member
• Posts: 14
##### Re: Chart Bounds & Legend Colour
« Reply #3 on: May 27, 2024, 01:06:28 am »
Hi WP,

Here's the code:

Code: Pascal  [Select][+][-]
1.         // Process point data...
3.         pSeriesXY.ShowLines:= false;
4.         pSeriesXY.ShowPoints:=true;
5.
6.         If pPointerSize=0 then
7.           pPointerSize := 15;
8.
9.         pSeriesXY.Pointer.HorizSize:=pPointerSize;
10.         pSeriesXY.Pointer.VertSize:=pPointerSize;

pX and pY are 34 and 27 respectively. There is no other data added to the chart. For good measure I've cleared all the series before add this single point. Am I missing something obvious in setting the chart properties?

I'll take a look at your notes regarding the legend in the morning.

#### wp

• Hero Member
• Posts: 12072
##### Re: Chart Bounds & Legend Colour
« Reply #4 on: May 27, 2024, 10:49:03 am »
This can't be all you are doing. Because having only one series with a single point would make the chart draw the point in its center and adjust the axis scale depending on the value of the point, very unlikely that the axis limits will be 0 and 100 in both directions. See the left chart in the attached project, it is created on the sole information that you are giving.

The second chart has a modification of the Range parameters of both axes. TChartAxis.Range holds two values, Min and Max, as well as to booleans, UseMin and UseMax, in order to activate these limits and to override the automatic axis scaling. After selecting them to 0 and 100, respectively, the axis limits are set exactly like that. But note that this works only as long as the series values are within this range, i.e. when a series value is > 100 or < 0 then automatic scaling comes in again and determines the corresponding axis limit. This was made to make sure that all data points are visible.

If you, by all means, want the axis limits to be 0 and 100, no matter what the series values are, you can set Chart.Extent.XMin, .XMax, .YMin, .YMax, .UseXMin, .UseXMax, .UseYMin, .UseYMax as you need.

#### sdawilson

• New Member
• Posts: 14
##### Re: Chart Bounds & Legend Colour
« Reply #5 on: May 27, 2024, 11:26:06 am »
Morning wp,

I've loaded your example and, just to confirm, yes, that's exactly what I'm doing. In the app, all carbon scores will range between either 0 and 100 or -100 and 100 on both axes. It's a tragically classic two-by-two scorecard plot.

Thank you, I've added the code you suggested, but now get the following error (see attachment).

#### sdawilson

• New Member
• Posts: 14
##### Re: Chart Bounds & Legend Colour
« Reply #6 on: May 27, 2024, 11:28:22 am »
Apologies, I'm an idiot! I added an X and Y! It compiles perfectly now.. just testing...

#### sdawilson

• New Member
• Posts: 14
##### Re: Chart Bounds & Legend Colour
« Reply #7 on: May 27, 2024, 11:32:38 am »
Still not working. Here's the code setting the axes:

Code: Pascal  [Select][+][-]
1. procedure Tform1.SetAxisAttributes();
2. begin
3.
4.   chtPlot.LeftAxis.Range.Min := pMinY;
5.   chtPlot.LeftAxis.Range.Max := pMaxY;
6.   chtPlot.LeftAxis.Marks.Range.Min := pMinY;
7.   chtPlot.LeftAxis.Marks.Range.Max := pMaxY;
8.   chtPlot.LeftAxis.Range.UseMax := true;
9.   chtPlot.LeftAxis.Range.UseMin := true;
10.   chtPlot.LeftAxis.Intervals.Count := pStopsY;
11.
12.   chtPlot.BottomAxis.Range.Min := pMinX;
13.   chtPlot.BottomAxis.Range.Max := pMaxX;
14.   chtPlot.BottomAxis.Marks.Range.Min := pMinX;
15.   chtPlot.BottomAxis.Marks.Range.Max := pMaxX;
16.   chtPlot.BottomAxis.Range.UseMax := true;
17.   chtPlot.BottomAxis.Range.UseMin := true;
18.   chtPlot.BottomAxis.Intervals.Count := pStopsX;
19.
20.   chtPlot.Extent.YMax := pMaxY;
21.   chtPlot.Extent.YMin := pMinY;
22.   chtPlot.Extent.XMax := pMaxX;
23.   chtPlot.Extent.XMin := pMinX;
24.   chtPlot.Extent.UseXMax := true;
25.   chtPlot.Extent.UseXMin := true;
26.   chtPlot.Extent.UseYMax := true;
27.   chtPlot.Extent.UseYMin := true;
28.
29.   chtPlot.ExtentSizeLimit.YMax := pMaxY;
30.   chtPlot.ExtentSizeLimit.YMin := pMinY;
31.   chtPlot.ExtentSizeLimit.XMax := pMaxX;
32.   chtPlot.ExtentSizeLimit.XMin := pMinX;
33.   chtPlot.ExtentSizeLimit.UseXMax := true;
34.   chtPlot.ExtentSizeLimit.UseXMin := true;
35.   chtPlot.ExtentSizeLimit.UseYMax := true;
36.   chtPlot.ExtentSizeLimit.UseYMin := true;
37.   application.ProcessMessages;
38.
39. end;

You can see I've added you new lines.

Any thoughts?

#### wp

• Hero Member
• Posts: 12072
##### Re: Chart Bounds & Legend Colour
« Reply #8 on: May 27, 2024, 12:27:47 pm »