Legend Trouble in code behind

6 posts, 0 answers
  1. Jeff Kershner
    Jeff Kershner avatar
    62 posts
    Member since:
    Aug 2009

    Posted 10 Sep 2010 Link to this post

    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
  2. Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 15 Sep 2010 Link to this post

    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
  3. Jeff Kershner
    Jeff Kershner avatar
    62 posts
    Member since:
    Aug 2009

    Posted 15 Sep 2010 Link to this post

    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?

  4. Bartholomeo Rocca
    Bartholomeo Rocca avatar
    247 posts
    Member since:
    May 2006

    Posted 16 Sep 2010 Link to this post

    Hi,

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


    Greetings,
    Bart.
  5. Jeff Kershner
    Jeff Kershner avatar
    62 posts
    Member since:
    Aug 2009

    Posted 16 Sep 2010 Link to this post

    I am failing to see how to change the background colors of the spider labels in the example that you sent.
  6. Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 22 Sep 2010 Link to this post

    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
Back to Top