Page 1 of 1
Adding a vertical custom axes - having different chart look
Posted: Mon Mar 23, 2009 1:43 pm
by 10550741
Hello
I would like to add vertical custom axes in order to display indicators like RSI and MACI.
I would like them to use the same horizontal axes but different vertical axes.
I saw the demo - see file I uploaded (SHIMON_chart_src.png)
What I need is a look more close to this (each series looks in a separate chart but still share the same x-axis) - see file SHIMON_char_dest.png how can I achieve that ?
Do I need to create different chart ? If so Can I share the same horizontal axes ?
Thanks
Shimon
Posted: Tue Mar 24, 2009 8:54 am
by yeray
Hi Shimon,
If I understand well, you would like to have a chart with one bottom axis and two vertical axes. And you would like a white zone between the two vertical axes.
1. The easiest way could be to have two charts (each one with its own axes).
2. You always could have one chart similar to the demo you pointed and draw custom shapes, lines and text directly to the canvas to hide the zone between the charts.
Posted: Tue Mar 24, 2009 9:36 am
by 10550741
Lets say I would like to Go in the (1) direction you offered.
Two chart each with its own axes.
I will make the top HORIZ axes invisible but how can I make the lower HORIZ axes look the same as the upper one.
In the upper chart I have a candle graph and I use the OnGetAxisLabel event.
I thought the lower chart could use the upper chart and send it the OnGetAxisLabel event so he can prepare the label for him but I received ValueIndex = -1 on that event....
Posted: Tue Mar 24, 2009 11:34 am
by 10550741
I am sorry having many questions but I use TeeChart for at least 6 month and very satisfied but some things are more complex...
I added a new chart to the panel for the RSI
Lets call upper chart as CHART_UP
Lets call lower chart (RSI) as CHART_LOW
My questions are:
1. I would like to have vertical grids in the same look as CHART_UP. I have access to CHART_UP and can copy parameters (if I would know, what...).
I know that the vertical grid depends on the label size but in the CHART_LOW I dont have the labels...
Is there a way to define the vertical grid in the CHART_LOW to be the same as CHART_UP ?
2. I don't want to see bottom axes labels in the CHART_LOW but I still want the tick marks, moreover I would like to remove the white are (pointed with green arrow) so the chart will be more compact.
How can I do that ?
3. I would like the charting area (the one closed with black rect) of CHART_LOW to be the same width like CHART_UP but currently you can see it is wider. How can I make them the same width ?
Thanks a lot for your time.
Posted: Tue Mar 24, 2009 11:36 am
by 10550741
Posted: Tue Mar 24, 2009 12:16 pm
by yeray
Hi Shimon,
Here you have an example I think that achieves the 3 things. I think it's easier to understand than to explain, but if you still find any problem don't hesitate to let us know and we'll try to explain it better or improve the code if there's something wrong.
Code: Select all
private
{ Private declarations }
procedure OnDrawBottomAxisLabels(Sender:TChartAxis; var X,Y,Z:Integer; var Text:String;
var DrawLabel:Boolean);
//...
var
Form1: TForm1;
candle1: TCandleSeries;
line1: TLineSeries;
rsiFunction1: TRSIFunction;
//...
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.View3D := false;
Chart2.View3D := false;
Chart1.Legend.Visible := false;
Chart2.Legend.Visible := false;
candle1 := TCandleSeries.Create(nil);
line1 := TLineSeries.Create(nil);
rsiFunction1 := TRSIFunction.Create(nil);
line1.SetFunction(rsiFunction1);
Chart1.AddSeries(candle1);
Chart2.AddSeries(line1);
candle1.FillSampleValues(25);
line1.DataSources.Add(candle1);
rsiFunction1.Period := 2;
Chart1.Draw;
Chart2.Axes.Bottom.IStartPos := Chart1.Axes.Bottom.IStartPos;
Chart2.Axes.Bottom.IEndPos := Chart1.Axes.Bottom.IEndPos;
Chart2.Axes.Bottom.SetMinMax(Chart1.Axes.Bottom.Minimum, Chart1.Axes.Bottom.Maximum);
Chart2.Axes.Bottom.OnDrawLabel := OnDrawBottomAxisLabels;
end;
procedure TForm1.OnDrawBottomAxisLabels(Sender: TChartAxis; var X, Y,
Z: Integer; var Text: String; var DrawLabel: Boolean);
begin
DrawLabel := false;
end;
Posted: Tue Mar 24, 2009 12:39 pm
by yeray
Hi Shimon,
Excuse me. For the point 2 you could try setting a bottom margin smaller:
Posted: Tue Mar 24, 2009 1:27 pm
by 10550741
Thanks for the help so far...
I have tried your code on an empty project and I have some issues with it.
My Chart1 (in the real application) has some traits
* Axes are on the right
* The format of the Y values are quite log ('0.0000')
* I am using ChartGetAxisLabel event
So to the form create you should add
chart1.RightAxis.AxisValuesFormat := '0.00001';
candle1.VertAxis := aRightAxis;
line1.VertAxis := aRightAxis;
chart1.ChartGetAxisLabel := ChartGetAxisLabel;
procedure TForm21.ChartGetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
ValueIndex: Integer; var LabelText: string);
begin
if (Sender = Chart1.BottomAxis) then
LabelText := '17';
end;
I have attached demo project named "SHIMONSOFER_RSI_SepChart.zip" using your attachments system.
In this case as you can see in the image
1) The the charting area width (rectangle) are different (because of the y values formatting)
2) The vertical axes grid of two charts are not aligned.
3) The Chart2 bottom margin did not disappear although I set MarginBottom = 0
Thanks again ...
Posted: Tue Mar 24, 2009 1:30 pm
by 10550741
Posted: Tue Mar 24, 2009 4:05 pm
by yeray
Hi Shimon,
1) Draw both charts and set the same left and right positions for chart2 than for chart1:
Code: Select all
Chart1.Draw;
Chart2.Draw;
Chart2.CustomChartRect := true;
Chart2.ChartRect.Left := Chart1.ChartRect.Left;
Chart2.ChartRect.Right := Chart1.ChartRect.Right;
Chart2.ChartRect.Bottom := Chart2.Height-10; // correct point 3
Chart2.Axes.Right.LabelsSize:=-10;
Chart2.Title.Visible := false;
2) They are not aligned because you are changing the labels text for chart1 and not for chart2. Then the vertical lines are recalculated in a different way for both charts. Why don't you use the same event to change the labels and to hide some of them?
Code: Select all
Chart1.Axes.Bottom.OnDrawLabel := OnDrawBottomAxisLabels;
Chart2.Axes.Bottom.OnDrawLabel := OnDrawBottomAxisLabels;
//...
procedure TForm21.OnDrawBottomAxisLabels(Sender: TChartAxis; var X, Y,
Z: Integer; var Text: String; var DrawLabel: Boolean);
begin
if (Sender = Chart1.BottomAxis) then
Text := '17'
else
DrawLabel := false;
end;
3) Already corrected at point 1
Posted: Tue Mar 24, 2009 6:26 pm
by 10550741
Thanks a lot for your reply.
I am really impressed from your skills and deep knowing.
Posted: Wed Mar 25, 2009 9:05 am
by yeray
Hi Shimon,
You are very welcome, even when I don't deserve these praises.