Help with Exchange() method

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
rackerson
Newbie
Newbie
Posts: 22
Joined: Mon Mar 08, 2004 5:00 am
Location: Edison, New Jersey USA

Help with Exchange() method

Post by rackerson » Thu Sep 21, 2006 8:51 pm

Delphi 6 Enterprise, TeeChart Pro 7.07

I am working with a simple pie chart. I want the user to be able to specify two indexes and have them swap position in the chart. I see an Exchange() method that is supposed to do that. Unfortunately, it doesn't appear to work correctly - that or I am really misunderstanding something.

I use the code: Series1.XValues.Exchange(1, 4);
where Series1 is a PieSeries that has 8 slices. I am trying to swap slices #1 and #4. When I run the code, the chart is never refreshed on screen. Repaint doesn't help, RefreshSeries doesn't help, and Invalidate doesn't help.

Tracing the code into the body of the TChartValueList.Exchange method in TeEngine.pas, I am able to watch the values in the local Value[] array. The values have indeed been swapped. Where the array used to list the numeric values (0, 1, 2, 3, 4, 5, 6, 7, 0...) it now lists (0, 4, 2, 3, 1, 5, 6, 7, 0...).

Unfortunately, the actual chart doesn't change on screen to reflect the values being updated. How can I make this refresh on screen?

The only workaround I have been able to determine thus far is to assign things to a temporary Series, exchange it, and then assign it back to my orignal chart. Please tell me there is a better way to accomplish my task.

Thank you,

Rich

Pep
Site Admin
Site Admin
Posts: 3299
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Mon Sep 25, 2006 11:12 am

Hi Rich,
the fatest way to use the Exchange method would be doing :

Code: Select all

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Series1.MandatoryValueList.Exchange(2,3);
Series1.Repaint;
end;

rackerson
Newbie
Newbie
Posts: 22
Joined: Mon Mar 08, 2004 5:00 am
Location: Edison, New Jersey USA

Post by rackerson » Mon Sep 25, 2006 3:31 pm

Hi Pep,

Thanks for the reply but unfortunately this did not do what I needed. Perhaps I phrased it wrong. I have a pie chart with sample data. My legend shows the numeric value associated with each pie slice and the label. The pie displays the value beside each slice.
The two slices 1 & 4 I was trying to swap in my example corresponded to the following:
  • index 1 - 720 Phones
    index 4 - 149 Lamps
What I want to do is keep the values with the labels but swap their display positions in the pie chart. On my current pie chart, the slice for Phones is larger than the one for Lamps due to its larger value. Similarly, they are different colors. Positionally, the Phones slice appears at the "top" of my chart while the Lamps slice appears closer to the "bottom".

My users simply want the ability to have the Lamps slice appear in the position of the Phones slice and the Phones slice move to the original location of the Lamps slice. The color, value, and label of each slice should remain unchanged. The ONLY thing I want to change is the slices' order in the chart.

The code sample you gave me simply swapped the numeric values of the slices. My legend, which used to report 720 Phones now said 149 Phones and the Lamps went from 149 Lamps to 720 Lamps. On the graph itself, while the numeric value of the slices were exchanged, the size of the slices did NOT change.

The end result was my smaller pie slice reported the larger value and the larger slice indicated the smaller value. Obviously this is not correct.

I know what I am trying to do can be done as it works when I assign to a temporary series, exchange items in the temporary series, and assign it back to the original chart. I am simply looking for a way to invoke methods to do this instead.

Thanks.

Pep
Site Admin
Site Admin
Posts: 3299
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Mon Oct 02, 2006 10:02 am

Hi,

ok, in that case, I'm afraid that the only way that I know of is the one used by you, by using a temporary Series.

Post Reply