Bubble chart axis

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
h.hasenack
Newbie
Newbie
Posts: 32
Joined: Tue Jul 21, 2009 12:00 am
Location: Nijmegen, Netherlands

Bubble chart axis

Post by h.hasenack » Fri Jul 16, 2010 9:59 am

Hi

a short description of the problem.
X - STate (points 1 .. 100)
Y - Importance (points 1 .. 100)
Size - Value (Currency 1,00 .. 1.000.0000.000,00)

When drawing the bubbe chart, the X and Y axis are adjusted so that the bubbele will fit. I'd rather have a separate axis for the bubble size, or somehow scale the bubble (rendered) size independent of the X and Y axis.
I'd like it even better if the right axis could be used to determine the numerical value of the bubble size.

It would be nice to be able to retrieve the actual bubble value when moving over it with the mouse, my solution now is to scale the bubble using some cusom code and reapply the factor when displaying the value. Unfortunately this drops the possibility to extract (unscaled) bubble values using the data manipulator available in the teechart editor.

Any Idea's

Regards - Hans

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Bubble chart axis

Post by Yeray » Fri Jul 16, 2010 2:30 pm

Hi Hans,

I think a screenshot of your actual program would help us to understand how are you exactly drawing your custom/right axis, what it represents, and what values you want to show when the mouse is over a bubble.
But with MarkTipsTool, I think you could show the information you want configuring the OnGetMarkText event:

Code: Select all

procedure TForm1.Series1GetMarkText(Sender: TChartSeries; ValueIndex: Integer; var MarkText: string);
begin
  MarkText:='X: ' + FloatToStr(Series1.XValue[ValueIndex]) + #13 +
            'Y: ' + FloatToStr(Series1.YValue[ValueIndex]) + #13 +
            'Radius: ' + FloatToStr(Series1.RadiusValues[ValueIndex]);
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

h.hasenack
Newbie
Newbie
Posts: 32
Joined: Tue Jul 21, 2009 12:00 am
Location: Nijmegen, Netherlands

Re: Bubble chart axis

Post by h.hasenack » Mon Jul 19, 2010 7:37 am

Please Check Bubble A and Bubble B in the attachment. (both .bmp and .tee)
Vert: State
Horiz: Importance
Bubble size: value that represents the sum of assets (either money:bubbleA, or counts:bubbleB)

Importance and state cannot be negative values, and are somewhere between 0..100
The object value, however, can be quite large depending on the replacement value of the objects involved. (BubbleA)

Since the bubble size is projected on the Vert axis, the vert axis scales to -28K..28K, while actual bubble center values are only between 0..100. This makes it impossible to read the Y position of a bubble. The horiz appears to be independent of the bubble size, that's OK.

I would like to be able to make the left axis also independent of the bubble size, and optionally have a separate vertical axis for the bubble size (right axis, top axis?). allowing my left and bottom axis to determine bubble position, and a right (or top) axis to read the bubble size from.

I hope this clarifies the problem enough.

Regards - Hans
Attachments
TeeBubbles.zip
(65.03 KiB) Downloaded 351 times

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Bubble chart axis

Post by Yeray » Mon Jul 19, 2010 12:27 pm

Hi Hans,

If I understood well, you have something like this and you would like to see clearer the difference in the YValue (center of the bubbles):

Code: Select all

uses Series, BubbleCh;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
    Series1: TBubbleSeries;
begin
  Chart1.View3D:=false;

  Series1:=Chart1.AddSeries(TBubbleSeries) as TBubbleSeries;

  for i:=0 to 10 do
    Series1.AddBubble(i, Random(10)-5, random(28000), '', clBlue);
end;
I don't know how you would like to notate the "little" differences in the YValue (center) showing at the same time the differences in the "big" radius.
If you have centers from -5 to 5, for example, and radius from -28000 to 28000, I understand as an expected behaviour that the differences in the centers won't be noticeable.

What you could do, for example, is to change the radius, dividing them by 10000 so that the differences in the centers will be comparable to the radius values.
But then the axis scale won't represent the radius values correctly. And to work around it, you could use the marks, for example:

Code: Select all

procedure Series1GetMarkText(Sender: TChartSeries; ValueIndex: Integer; var MarkText: string);

//...

uses BubbleCh;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
    Series1: TBubbleSeries;
    ChartTool1: TMarksTipTool;
begin
  Chart1.View3D:=false;

  Series1:=Chart1.AddSeries(TBubbleSeries) as TBubbleSeries;

  for i:=0 to 10 do
    Series1.AddBubble(i, Random(10)-5, random(28000), '', clBlue);

  //modifications
  for i:=0 to Series1.Count-1 do
  begin
    Series1.Labels[i]:=FormatFloat('#.##0,###', Series1.RadiusValues[i]);
    Series1.RadiusValues[i]:=Series1.RadiusValues[i]/10000;
  end;

  Series1.OnGetMarkText:=Series1GetMarkText;

  ChartTool1:=Chart1.Tools.Add(TMarksTipTool) as TMarksTipTool;
end;

procedure TForm1.Series1GetMarkText(Sender: TChartSeries; ValueIndex: Integer; var MarkText: string);
var series: TBubbleSeries;
begin
  if Sender is TBubbleSeries then
  begin
    series:=Sender as TBubbleSeries;
    MarkText:='X: ' + FloatToStr(series.XValue[ValueIndex]) + #13 + 'Y: ' + FloatToStr(series.YValue[ValueIndex]) + #13 + 'Radius: ' + (series.Labels[ValueIndex]);
  end;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

h.hasenack
Newbie
Newbie
Posts: 32
Joined: Tue Jul 21, 2009 12:00 am
Location: Nijmegen, Netherlands

Re: Bubble chart axis

Post by h.hasenack » Mon Jul 19, 2010 2:13 pm

Indeed, I could make the bubbels smaller by scaling down my values. The downside is that when exporting data, the data would need to be scaled back in order to export the data that I wanted to displayh in the first place :(

The thing is the bubble diagram is used as a kind of 3 dimensional display. (I use TTowerseries to display the same data es well)

Therefore I'd like an (optional) 3rd axis for the bubble diameter, making sure the Y position axis is independent of the bubble diameter.

Hint: You may consider this as a feature request. I am already creating a solution based on the scaling of the bubbles using a factor, or log10. But even in that case I'd want my diameter data to be independent of the (X,Y) position of the bubbles.

Regards - Hans

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Bubble chart axis

Post by Yeray » Mon Jul 19, 2010 4:06 pm

Hi Hans,

And what about using TPoint3DSeries or TBubble3DSeries and activating the Depth Right axis? Then you could use the Z instead of the Radius. I think it would become like follows:
YValues: State
XValues: Importance
ZValues: value that represents the sum of assets
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

h.hasenack
Newbie
Newbie
Posts: 32
Joined: Tue Jul 21, 2009 12:00 am
Location: Nijmegen, Netherlands

Re: Bubble chart axis

Post by h.hasenack » Wed Aug 25, 2010 12:35 pm

Hi Yeray

I've made some adjustments to BubbleCH.pas I'd like to share with you. You may consider takem them into a next release. The changes implement a 'RadiusScaleFactor' which allows (display) scaling of the bubbles whilst still keeping the original radius values. My 1st choice would be to have a separate axis for the bubble radius, but I can live with thios solution too.

Code: Select all

// changes to the class TBubbleSeries
private
{$ifdef HH_PATCH_TC_BUBBLE}
    FRadiusScaleFactor : double;
{$endif}
protected
{$ifdef HH_PATCH_TC_BUBBLE}
    procedure SetRadiusScaleFactor(aFactor:double);
    function HasRadiusScaleFactor:boolean;
{$endif}

published
{$ifdef HH_PATCH_TC_BUBBLE}
    property RadiusScaleFactor:double read FRadiusScaleFactor write SetRadiusScaleFactor stored HasRadiusScaleFactor;
{$endif}

// changes made to implementation
constructor
{$ifdef HH_PATCH_TC_BUBBLE}
  FRadiusScaleFactor :=1.0;
{$endif}

Procedure TBubbleSeries.PreparePointer(ValueIndex:Integer);
var tmpSize : Integer;
begin

{$ifdef HH_PATCH_TC_BUBBLE}
  tmpSize:=GetVertAxis.CalcSizeValue(RadiusValues.Value[ValueIndex]*RadiusScaleFactor);
{$else}
  tmpSize:=GetVertAxis.CalcSizeValue(RadiusValues.Value[ValueIndex]);
{$endif}
...

// applyradius

  if Increment then
     result:=Math.Max(result,AList.Value[t]+RadiusValues.Value[t]{$ifdef HH_PATCH_TC_BUBBLE}*RadiusScaleFactor{$endif})
  else
     result:=Math.Min(result,AList.Value[t]-RadiusValues.Value[t]{$ifdef HH_PATCH_TC_BUBBLE}*RadiusScaleFactor{$endif});

// Assign
{$ifdef HH_PATCH_TC_BUBBLE}
  if Source is TBubbleSeries then
     FRadiusScaleFactor:=TBubbleSeries(Source).FRadiusScaleFactor;
{$endif}

// 2 new routines
{$ifdef HH_PATCH_TC_BUBBLE}

procedure TBubbleSeries.SetRadiusScaleFactor(aFactor:double);
begin
  if FRadiusScaleFactor<>aFactor then
  begin
    if aFactor<=0 then
      raise ChartException.CreateFmt('%s.SetRadiusScaleFactor(%n) in valid value',[ClassName,aFactor])
    else
    begin
      FRadiusScaleFactor:=aFactor;
      Repaint;
    end;
  end;

end;

function TBubbleSeries.HasRadiusScaleFactor:boolean;
begin
  Result:=FRadiusScaleFactor<>1.0;
end;
{$endif}

I can send you the changed BubbleCH.pas if you want to. I guessed you dont want me do drop the entire source code here ;)

Regards - Hans

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Bubble chart axis

Post by Yeray » Fri Aug 27, 2010 11:21 am

Hi Hans,

Thanks for your suggestions!
I've added it to the wish list to be revised asap (TV52015115).
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply