This is a migrated thread and some comments may be shown as answers.

Legend Trouble in code behind

5 Answers 54 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Jeff Kershner
Top achievements
Rank 1
Jeff Kershner asked on 10 Sep 2010, 11:44 PM
I am binding my data like this:
foreach (MarketShareData data in marketShareData)
{
    DataSeries lineSeries = new DataSeries();
    lineSeries.Definition = new LineSeriesDefinition();
    lineSeries.Add(new DataPoint() { YValue = data.marketshare0, XCategory = data.timeStamp0.ToShortDateString(), LegendLabel = data.company, Label = data.company });
    lineSeries.Add(new DataPoint() { YValue = data.marketshare1, XCategory = data.timeStamp1.ToShortDateString(), LegendLabel = data.company, Label = data.company });
    lineSeries.Add(new DataPoint() { YValue = data.marketshare2, XCategory = data.timeStamp2.ToShortDateString(), LegendLabel = data.company, Label = data.company });
    lineSeries.Add(new DataPoint() { YValue = data.marketshare3, XCategory = data.timeStamp3.ToShortDateString(), LegendLabel = data.company, Label = data.company });
    lineSeries.Add(new DataPoint() { YValue = data.marketshare4, XCategory = data.timeStamp4.ToShortDateString(), LegendLabel = data.company, Label = data.company });
    lineSeries.Definition.ShowItemLabels = false;
    chart.DefaultView.ChartArea.DataSeries.Add(lineSeries);
}

The Line Chart legend still shows Series 0, Series 1, Series 2, etc... as the legend text.  Shouldn't it show the LegendLabel as it is bound above?

Also, how do you get rid of the title of the legend which by default is "Legend"?

Thanks,
--Jeff

5 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 15 Sep 2010, 01:18 PM
Hello Jeff Kershner,

You should set the LegendLabel of the series like this:
lineSeries.LegendLabel = "<My Label>";

Setting the LegendLabel on the data point can be used when you want to use DataPointLabel mode for the ChartLegend. You can read more on Legend display modes in our help topic here.

Best wishes,
Yavor Ivanov
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Jeff Kershner
Top achievements
Rank 1
answered on 15 Sep 2010, 04:53 PM
Thanks, that worked... The last problem I am having is with the background of the spider label.

I am using the palette for the spider lines and this is working well.  How do I change the background of the spider labels to be transparent?

0
Bartholomeo Rocca
Top achievements
Rank 1
answered on 16 Sep 2010, 10:23 AM
Hi,

You need to set custom label style as demonstrated here: http://demos.telerik.com/silverlight/#Chart/NegativeValues.


Greetings,
Bart.
0
Jeff Kershner
Top achievements
Rank 1
answered on 16 Sep 2010, 04:46 PM
I am failing to see how to change the background colors of the spider labels in the example that you sent.
0
Yavor
Telerik team
answered on 22 Sep 2010, 06:59 AM
Hello Jeff Kershner,

You can change the Item Labels' background by applying a custom style to the SeriesItemLabel like this:
<Style x:Key="SeriesItemLabelStyle"
      TargetType="telerik:SeriesItemLabel">
                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                    <Setter Property="Padding" Value="2,0" />
                    <Setter Property="IsHitTestVisible" Value="False"/>
                    <Setter Property="Foreground" Value="Black"/>
                    <Setter Property="Template" >
                        <Setter.Value>
                            <ControlTemplate TargetType="telerik:SeriesItemLabel">
                                <Canvas x:Name="PART_MainContainer">
                                    <Path                           
                               Visibility="{TemplateBinding ConnectorVisibility}"
                               Style="{TemplateBinding ConnectorStyle}"
                               Stroke="{TemplateBinding Stroke}"
                               StrokeThickness="{TemplateBinding StrokeThickness}">
                                        <Path.Data>
                                            <PathGeometry >
                                                <PathGeometry.Figures>
                                                    <PathFigure x:Name="PART_Connector">
                                                        <PathFigure.Segments>
                                                            <PolyLineSegment />
                                                        </PathFigure.Segments>
                                                    </PathFigure>
                                                </PathGeometry.Figures>
                                            </PathGeometry>
                                        </Path.Data>
                                    </Path>
                                    <Border
                                x:Name="PART_TextContainer"
                                Style="{TemplateBinding LabelStyle}"
                                BorderBrush="{TemplateBinding Stroke}">
                                        <TextBlock
                                    TextAlignment="{TemplateBinding HorizontalContentAlignment}"
                                    Margin="{TemplateBinding Padding}"
                                    Text="{TemplateBinding Content}" />
                                    </Border>
                                </Canvas>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>

You can read more on styling the Item Labels in this topic in our help system.

Regards,
Yavor Ivanov
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
Chart
Asked by
Jeff Kershner
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Jeff Kershner
Top achievements
Rank 1
Bartholomeo Rocca
Top achievements
Rank 1
Share this question
or