legend with checkbox style
Re: legend with checkbox style
Also the expected output can be seen if you delete the series when you uncheck the checkboxes and add the series if you check the checkboxes.
Re: legend with checkbox style
Hi shikha,
Then, if I understand well, you would like the clicked series to disappear, redraw the stacked bar as if the series would have been removed completely, but maintain its mark. If so, I'm afraid that the examples above aren't doing what you want. Instead of that, you simply should hide all the marks and draw them manually:
Then, if I understand well, you would like the clicked series to disappear, redraw the stacked bar as if the series would have been removed completely, but maintain its mark. If so, I'm afraid that the examples above aren't doing what you want. Instead of that, you simply should hide all the marks and draw them manually:
Code: Select all
private void InitializeChart()
{
chartController1.Chart = tChart1;
tChart1.Aspect.View3D = false;
for (int i = 0; i < 4; i++)
{
new Bar(tChart1.Chart);
tChart1[i].FillSampleValues(5);
tChart1[i].Marks.Visible = false;
for (int j = 0; j < tChart1[0].Count; j++)
{
new Annotation(tChart1.Chart);
}
}
(tChart1[0] as Bar).MultiBar = MultiBars.Stacked;
tChart1.Legend.CheckBoxes = true;
tChart1.Legend.Alignment = Steema.TeeChart.LegendAlignments.Bottom;
tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
tChart1.ClickLegend += new MouseEventHandler(tChart1_ClickLegend);
tChart1.Draw();
}
void tChart1_ClickLegend(object sender, MouseEventArgs e)
{
tChart1.Draw();
}
void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
double YPos;
int ToolIndex = 0;
int height = (tChart1.Tools[ToolIndex] as Annotation).Shape.Height;
for (int ValueIndex = 0; ValueIndex < tChart1[0].Count; ValueIndex++)
{
YPos = 0;
for (int SeriesIndex = 0; SeriesIndex < tChart1.Series.Count; SeriesIndex++)
{
if (tChart1[SeriesIndex].Active)
{
(tChart1.Tools[ToolIndex] as Annotation).Top = (int)(tChart1.Axes.Left.CalcYPosValue(YPos + (tChart1[SeriesIndex].YValues[ValueIndex] / 2))) - height / 2;
YPos += tChart1[SeriesIndex].YValues[ValueIndex];
}
else
{
(tChart1.Tools[ToolIndex] as Annotation).Top = tChart1.Axes.Left.CalcPosValue(YPos) - height / 2;
}
(tChart1.Tools[ToolIndex] as Annotation).Text = tChart1[SeriesIndex].YValues[ValueIndex].ToString();
(tChart1.Tools[ToolIndex] as Annotation).Left = tChart1[SeriesIndex].CalcXPos(ValueIndex) + (tChart1[0] as Bar).BarBounds.Width / 2 - (tChart1.Tools[ToolIndex] as Annotation).Width / 2;
ToolIndex += 1;
}
}
}
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: legend with checkbox style
Thanks so much. As you know i am using vb.net, so i converted it iusing a utility(http://www.developerfusion.com/tools/co ... arp-to-vb/). But i am getting some errors -
1. chartController1 is not declared.( what is chartController1?)
2. New Annotation(tChart1.Chart) -at this line, syntax error. - whts annotation?
3. TryCast(tChart1(0), Bar).MultiBar = MultiBars.Stacked -at this line,ERROR-value of series can't be converted into tchart.bar
1. chartController1 is not declared.( what is chartController1?)
2. New Annotation(tChart1.Chart) -at this line, syntax error. - whts annotation?
3. TryCast(tChart1(0), Bar).MultiBar = MultiBars.Stacked -at this line,ERROR-value of series can't be converted into tchart.bar
Re: legend with checkbox style
the same output (errors ) are achieved when i use the utility u advised to use( Kamalpatel and carlosag)
Re: legend with checkbox style
Hi shikha,
1. ChartController is a TeeChart component that allows the programmer access to some TeeChart features at runtime such as the editor.
2. Annotation is a TeeChart tool that allows the programmer to draw a square with text in a custom position. In this case we use as many annotations as marks in order to replace ones for the others. Note that we are repositioning them at OnAfterDraw event in odrer to take in consideration new bars positions after enabling/disabling a series from the legend checkboxes.
3. This code works fine for us here. Note that is the code that carlosag translator gave me with a few modifications. And also note that you'll need a chart and a chartcontroller added at design time in order to run it:
1. ChartController is a TeeChart component that allows the programmer access to some TeeChart features at runtime such as the editor.
2. Annotation is a TeeChart tool that allows the programmer to draw a square with text in a custom position. In this case we use as many annotations as marks in order to replace ones for the others. Note that we are repositioning them at OnAfterDraw event in odrer to take in consideration new bars positions after enabling/disabling a series from the legend checkboxes.
3. This code works fine for us here. Note that is the code that carlosag translator gave me with a few modifications. And also note that you'll need a chart and a chartcontroller added at design time in order to run it:
Code: Select all
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
InitializeChart()
End Sub
Private Sub InitializeChart()
chartController1.Chart = tChart1
tChart1.Aspect.View3D = False
Dim i As Integer = 0
Do While (i < 4)
TChart1.Series.Add(New Steema.TeeChart.Styles.Bar)
tChart1(i).FillSampleValues(5)
tChart1(i).Marks.Visible = False
Dim j As Integer = 0
Do While (j < tChart1(0).Count)
TChart1.Tools.Add(New Steema.TeeChart.Tools.Annotation)
j = (j + 1)
Loop
i = (i + 1)
Loop
CType(TChart1(0), Steema.TeeChart.Styles.Bar).MultiBar = Steema.TeeChart.Styles.MultiBars.Stacked
tChart1.Legend.CheckBoxes = True
tChart1.Legend.Alignment = Steema.TeeChart.LegendAlignments.Bottom
AddHandler tChart1.AfterDraw, AddressOf Me.tChart1_AfterDraw
AddHandler tChart1.ClickLegend, AddressOf Me.tChart1_ClickLegend
tChart1.Draw()
End Sub
Private Sub tChart1_ClickLegend(ByVal sender As Object, ByVal e As MouseEventArgs)
tChart1.Draw()
End Sub
Private Sub tChart1_AfterDraw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D)
Dim YPos As Double
Dim ToolIndex As Integer = 0
Dim height As Integer = CType(TChart1.Tools(ToolIndex), Steema.TeeChart.Tools.Annotation).Shape.Height
Dim ValueIndex As Integer = 0
Do While (ValueIndex < tChart1(0).Count)
YPos = 0
Dim SeriesIndex As Integer = 0
Do While (SeriesIndex < tChart1.Series.Count)
If tChart1(SeriesIndex).Active Then
CType(TChart1.Tools(ToolIndex), Steema.TeeChart.Tools.Annotation).Top = (CType(TChart1.Axes.Left.CalcYPosValue((YPos _
+ (TChart1(SeriesIndex).YValues(ValueIndex) / 2))), Integer) _
- (height / 2))
YPos = (YPos + tChart1(SeriesIndex).YValues(ValueIndex))
Else
CType(TChart1.Tools(ToolIndex), Steema.TeeChart.Tools.Annotation).Top = (TChart1.Axes.Left.CalcPosValue(YPos) _
- (height / 2))
End If
CType(TChart1.Tools(ToolIndex), Steema.TeeChart.Tools.Annotation).Text = TChart1(SeriesIndex).YValues(ValueIndex).ToString
CType(TChart1.Tools(ToolIndex), Steema.TeeChart.Tools.Annotation).Left = (TChart1(SeriesIndex).CalcXPos(ValueIndex) _
+ ((CType(TChart1(0), Steema.TeeChart.Styles.Bar).BarBounds.Width / 2) _
- (CType(TChart1.Tools(ToolIndex), Steema.TeeChart.Tools.Annotation).Width / 2)))
ToolIndex = (ToolIndex + 1)
SeriesIndex = (SeriesIndex + 1)
Loop
ValueIndex = (ValueIndex + 1)
Loop
End Sub
End Class
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: legend with checkbox style
Thanks so much.. it looks great.. only 1 thing- i dont want to show chart controller,. is there any specific reason we are using it here.. or i can just delete it .. if not can i hide it(how).thanks
Re: legend with checkbox style
Hi shikha,
Yes, of course you can simply remove any reference to chartcontroller. It's only a tool we often use to easily test things.
Yes, of course you can simply remove any reference to chartcontroller. It's only a tool we often use to easily test things.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: legend with checkbox style
great,but unfortunately its having the issue with which we strated with that is when i uncheck all the checkboxes it should keep the labels of x axis intact. but this is not happening. also there are values of y axis displayed on bars which i dont want.can this be done?
Re: legend with checkbox style
Hi shikha,
Axis labels? Weren't we talking about series' marks? I'm afraid that I haven't understood the problem correctly from a beginning and I'm not sure if you have understood what my examples were trying to achieve.
So it would be better if you could explain the problem from zero as precisely as you can and if you could send us a simple example project we can run as-is to see the issue here from the beginning. (note that now you can attach files directly to the forums)
And finally I'd like to apologize for the time lost going around to this (at first look simple) issue.
Axis labels? Weren't we talking about series' marks? I'm afraid that I haven't understood the problem correctly from a beginning and I'm not sure if you have understood what my examples were trying to achieve.
So it would be better if you could explain the problem from zero as precisely as you can and if you could send us a simple example project we can run as-is to see the issue here from the beginning. (note that now you can attach files directly to the forums)
And finally I'd like to apologize for the time lost going around to this (at first look simple) issue.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: legend with checkbox style
Oh!!
I have a bar chart with checkbox style legend at bottom. i am using multistacked bar chart. So at bottom is series1 and on taht series2 and on that series3. Suppose there are 2 bars and each bar has 3 series stacked on each other. The legend is showing series1,series2,series3 with its respective checkboxes. Now
1. when user uncheck checkbox of say series1 then both bars should be changed in sense that series 1 should dissapear and series2 and series 3 which were stacked on series1, should come down and touch x axis ( as if the series1 is deleted). But series1 checkbox and its associates series1 label in LEGEND should remain. ALSO the X axis label of bar1 and bar2 should also remain. AND even if user unchecks all checkboxes of legend( taht is series1,series2,series3 ), then too the
X axis label of bar1 and bar2 should remain. Also all the checkboxes and their associated label which are next to checkboxes in legend ( i m not sure what u call them legend key/label ?) should also remain.
I hope it is clear.. if not please let me know.. i m nopt sure how to show with example project as i am noyt able to generate expected output, right.. so it will not help i think?
I have a bar chart with checkbox style legend at bottom. i am using multistacked bar chart. So at bottom is series1 and on taht series2 and on that series3. Suppose there are 2 bars and each bar has 3 series stacked on each other. The legend is showing series1,series2,series3 with its respective checkboxes. Now
1. when user uncheck checkbox of say series1 then both bars should be changed in sense that series 1 should dissapear and series2 and series 3 which were stacked on series1, should come down and touch x axis ( as if the series1 is deleted). But series1 checkbox and its associates series1 label in LEGEND should remain. ALSO the X axis label of bar1 and bar2 should also remain. AND even if user unchecks all checkboxes of legend( taht is series1,series2,series3 ), then too the
X axis label of bar1 and bar2 should remain. Also all the checkboxes and their associated label which are next to checkboxes in legend ( i m not sure what u call them legend key/label ?) should also remain.
I hope it is clear.. if not please let me know.. i m nopt sure how to show with example project as i am noyt able to generate expected output, right.. so it will not help i think?
Re: legend with checkbox style
Hi shikha,
Probably you should use custom labels as in the example at All Features/Welcome !\Axes\Labels\Custom labels demo. (You should find new features demos at TeeChart programs group).
I'm not sure to understand that, having Multibar as stacked, how is your bottom axis showing more than one series label. Here probably there is something that I'm still unable to understand. But anyway, the easiest would be using custom labels as in the example I said above.
Probably you should use custom labels as in the example at All Features/Welcome !\Axes\Labels\Custom labels demo. (You should find new features demos at TeeChart programs group).
I'm not sure to understand that, having Multibar as stacked, how is your bottom axis showing more than one series label. Here probably there is something that I'm still unable to understand. But anyway, the easiest would be using custom labels as in the example I said above.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: legend with checkbox style
i am already using custom labels. But thats not the issue, the issue is as i mentioned above. I am uploading screenshot for ur reference.
Re: legend with checkbox style
I think there is communication gap.. so i will try again to describe more clearly-
I am uploading the application "BARCHART.zip" which depicts what i have existing. Now the issue is that when i uncheck all the checkboxes the X axis labels dissapear(please note it happens only in case when u click ALL checkboxes, else user can see X axis labels ie for example if only one checkbox of legend is unclicked ).
"So What I want is that when i uncheck all the checkboxes in legend , even then the X axis labels should remain visible. "THAts it.
I am uploading the application "BARCHART.zip" which depicts what i have existing. Now the issue is that when i uncheck all the checkboxes the X axis labels dissapear(please note it happens only in case when u click ALL checkboxes, else user can see X axis labels ie for example if only one checkbox of legend is unclicked ).
"So What I want is that when i uncheck all the checkboxes in legend , even then the X axis labels should remain visible. "THAts it.
Re: legend with checkbox style
Also just to make it even more clear
to reproduce the issue, the steps are-
1. click bar1,bar2,bar3 corresponding checkboxes in legend.
2. Now see the x axis label- the labels cd,bg,rea have dissapeared. But I WANT TO THEM TO BE VISIBLE EVEN IN THIS CASE!!!!
If you see this post from start this is what i was trying to describe, may be i was not very clear, sorry abt that.Can you let me know how to go abt it.. as its very urgent.. maany tahnks in advance.
to reproduce the issue, the steps are-
1. click bar1,bar2,bar3 corresponding checkboxes in legend.
2. Now see the x axis label- the labels cd,bg,rea have dissapeared. But I WANT TO THEM TO BE VISIBLE EVEN IN THIS CASE!!!!
If you see this post from start this is what i was trying to describe, may be i was not very clear, sorry abt that.Can you let me know how to go abt it.. as its very urgent.. maany tahnks in advance.
Re: legend with checkbox style
Hi shikha,
I've added the following code to yours and, if I've understood well this time, I think it achieves what you are trying to do:
I've added the following code to yours and, if I've understood well this time, I think it achieves what you are trying to do:
Code: Select all
' force a first repaint to set minimum and maximum for the axes
TChart1.Draw()
' now you can force the axis not to move
TChart1.Axes.Left.Automatic = False
TChart1.Axes.Bottom.Automatic = False
' you could add a dummy series (series without data) to force axis to be always drawn
TChart1.Series.Add(New Steema.TeeChart.Styles.Bar())
TChart1.Series(TChart1.Series.Count - 1).ShowInLegend = False
' you should finally clear the bottom axis labels and draw the ones you wish
TChart1.Axes.Bottom.Labels.Items.Clear()
TChart1.Axes.Bottom.Labels.Items.Add(0, "label 1")
TChart1.Axes.Bottom.Labels.Items.Add(1, "label 2")
TChart1.Axes.Bottom.Labels.Items.Add(2, "label 3")
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |