Hello Pixie,
Thank you for writing.
In order to achieve your goal, you can subscribe to the ChartElement.LegendElement.VisualItemCreating event and replace the default LegendItemElement with your custom one containing a RadCheckBoxElement. Here is a sample code snippet:
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Telerik
Thank you for writing.
In order to achieve your goal, you can subscribe to the ChartElement.LegendElement.VisualItemCreating event and replace the default LegendItemElement with your custom one containing a RadCheckBoxElement. Here is a sample code snippet:
public
Form1()
{
InitializeComponent();
this
.radChartView1.ChartElement.LegendElement.VisualItemCreating += LegendElement_VisualItemCreating;
BarSeries barSeries =
new
BarSeries(
"Performance"
,
"RepresentativeName"
);
barSeries.LegendTitle =
"Q1"
;
barSeries.DataPoints.Add(
new
CategoricalDataPoint(177,
"Harley"
));
barSeries.DataPoints.Add(
new
CategoricalDataPoint(128,
"White"
));
barSeries.DataPoints.Add(
new
CategoricalDataPoint(143,
"Smith"
));
barSeries.DataPoints.Add(
new
CategoricalDataPoint(111,
"Jones"
));
barSeries.DataPoints.Add(
new
CategoricalDataPoint(118,
"Marshall"
));
this
.radChartView1.Series.Add(barSeries);
BarSeries barSeries2 =
new
BarSeries(
"Performance"
,
"RepresentativeName"
);
barSeries2.LegendTitle =
"Q2"
;
barSeries2.DataPoints.Add(
new
CategoricalDataPoint(153,
"Harley"
));
barSeries2.DataPoints.Add(
new
CategoricalDataPoint(141,
"White"
));
barSeries2.DataPoints.Add(
new
CategoricalDataPoint(130,
"Smith"
));
barSeries2.DataPoints.Add(
new
CategoricalDataPoint(88,
"Jones"
));
barSeries2.DataPoints.Add(
new
CategoricalDataPoint(109,
"Marshall"
));
this
.radChartView1.Series.Add(barSeries2);
this
.radChartView1.ShowLegend =
true
;
this
.radChartView1.LegendTitle =
"Legend"
;
}
private
void
LegendElement_VisualItemCreating(
object
sender, LegendItemElementCreatingEventArgs e)
{
e.ItemElement =
new
CustomLegendItemElement(e.LegendItem);
}
public
class
CustomLegendItemElement : LegendItemElement
{
public
CustomLegendItemElement(LegendItem item) :
base
(item)
{
}
RadCheckBoxElement cb =
new
RadCheckBoxElement();
protected
override
void
CreateChildElements()
{
base
.CreateChildElements();
this
.MarkerElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
cb.ToggleState = Telerik.WinControls.Enumerations.ToggleState.On;
this
.Children.Add(cb);
cb.ToggleStateChanged += cb_ToggleStateChanged;
}
private
void
cb_ToggleStateChanged(
object
sender, StateChangedEventArgs args)
{
if
(args.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
{
this
.LegendItem.Element.IsVisible =
true
;
}
else
{
this
.LegendItem.Element.IsVisible =
false
;
}
}
}
I hope this information helps. Should you have further questions I would be glad to help.
Dess
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items