Page 1 of 1
Extra legend tool
Posted: Thu Apr 15, 2010 5:44 am
by 13045482
Hi
i have a series which i want to show in the chart but not in the main legend of chart. But i do want to show it in Extra legend (tool). Also i want to change this series title when its displayed in extra legend.
So for example series title= A and this series is not showed in main legend of chart. But its showing up in the extra legend (tool) that i have added to the chart with series name "B". Is there any way to do this this?
Re: Extra legend tool
Posted: Thu Apr 15, 2010 10:06 am
by yeray
Hi shikha,
I can see two options:
- Working with groups. You could create a group for each series so the group can have a different name than the series and the extra legend style could be Groups to show that. And you can show the series you want in the default legend with Series.ShowInLegend boolean.
- Drawing manually your custom legend(s) using canvas Rectangle and TextOut methods at OnAfterDraw event.
Re: Extra legend tool
Posted: Thu Apr 15, 2010 10:58 am
by 13045482
great.. can you please give me example code of both these methods..i am a bit new to these... Also is it possible that if i have a series with name say "A" , can i show it in the main legend of tchart with diffrent series name( i.e..legend style is set to series name , i can't change that as for some series i am showing in legend i want to display series name.. but for some series i want to display custom text)... so in other words i want thta some seies shown in legend should be displayed with series name and some should be displayed with custom text..how to do that?
Re: Extra legend tool
Posted: Thu Apr 15, 2010 11:19 am
by 13045482
Just to add I TRIED USING gettext method but how would i know which series to change at GetLegendText event. The series for which i need the series name to change is
Dim EndPointMark As Steema.TeeChart.Styles.Points
EndPointMark.Pointer.Style = Steema.TeeChart.Styles.PointerStyles.Circle
EndPointMark.Title = SeriesName & stype
So how can i know when this circle type series is hit at the code below?
Private Sub tcCurve_GetLegendText(ByVal sender As Object, ByVal e As Steema.TeeChart.GetLegendTextEventArgs) Handles tcCurve.GetLegendText
e.Text = "kk"
End Sub
Re: Extra legend tool
Posted: Thu Apr 15, 2010 2:55 pm
by yeray
Hi
Excuse me, the first option I proposed isn't possible right now because the LegendStyle SeriesGroups isn't available in NET yet. It's a feature already in the wish list (TF02014762).
Here it is an example to draw a custom legend:
Code: Select all
private bool[] ShowInCustomLegend;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
int nSeries = 4;
ShowInCustomLegend = new bool[nSeries];
for (int i = 0; i < nSeries; i++)
{
new Steema.TeeChart.Styles.Bar(tChart1.Chart);
tChart1[i].FillSampleValues();
ShowInCustomLegend[i] = true;
}
tChart1[2].ShowInLegend = false;
tChart1[3].ShowInLegend = false;
ShowInCustomLegend[0] = false;
ShowInCustomLegend[1] = false;
tChart1.Draw();
tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
}
void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
drawCustomLegend(g);
}
private void drawCustomLegend(Steema.TeeChart.Drawing.Graphics3D g)
{
int RectHeight = 0;
int RectWidth = 0;
int RectLeft, RectTop, tmp;
for (int i = 0; i < ShowInCustomLegend.Length; i++)
{
if (ShowInCustomLegend[i])
{
RectHeight = RectHeight + (int)g.TextHeight(tChart1[i].ToString());
RectWidth = (int)g.TextWidth(tChart1[i].ToString());
}
}
RectWidth = RectWidth + 31;
RectHeight = RectHeight + 2;
RectLeft = tChart1.Legend.Left;
RectTop = tChart1.Legend.Bottom + 10;
g.Rectangle(RectLeft, RectTop, RectLeft + RectWidth, RectTop + RectHeight);
tmp = 1;
for (int i = 0; i < ShowInCustomLegend.Length; i++)
{
if (ShowInCustomLegend[i])
{
g.Pen.Color = ((Steema.TeeChart.Styles.Bar)tChart1[i]).Pen.Color;
g.Brush.Color = tChart1[i].Color;
g.Rectangle(RectLeft + 6, RectTop + tmp + 2, RectLeft + 5 + 10, RectTop + tmp + 12);
g.TextOut(RectLeft + 21, RectTop + tmp, tChart1[i].ToString());
tmp = tmp + (int)g.TextHeight(tChart1[i].ToString());
}
}
}