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

RedChart Legend is Empty

1 Answer 56 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Li
Top achievements
Rank 1
Li asked on 10 Mar 2011, 04:19 AM
Hi,
After a long time ,I suddenly found the Legend is empty.
But I don't know how it comes.
Please Help.
Thank you~


<
UserControl
    x:Class="CE.Views.ReserveChart"
    xmlns:telerikQuickStart="clr-namespace:Telerik.Windows.Controls.QuickStart;assembly=Telerik.Windows.Controls"
    xmlns:example="clr-namespace:CE.Core"
    d:DesignWidth="1280" d:DesignHeight="750" mc:Ignorable="d"
    >
 
    <UserControl.Resources>
        <example:ExampleViewModel x:Key="DataContext" />
        <LinearGradientBrush x:Key="LegendItem1Background" EndPoint="1,0" StartPoint="0,0" SpreadMethod="Repeat">
            <LinearGradientBrush.RelativeTransform>
                <CompositeTransform CenterY="0.5" CenterX="0.5" Rotation="90"/>
            </LinearGradientBrush.RelativeTransform>
            <GradientStop Color="#7FFFFF7D" Offset="1"/>
            <GradientStop Color="#7FE83828"/>
        </LinearGradientBrush>
 
        <Style x:Key="CustomStyle" TargetType="telerik:StepArea">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="telerik:StepArea">
                        <Canvas>
                            <Rectangle x:Name="PART_DefiningGeometry"
                                   Height="{TemplateBinding ItemActualHeight}"
                                   Width="{TemplateBinding ItemActualWidth}"
                                   StrokeThickness="0"/>
                            <Canvas.RenderTransform>
                                <ScaleTransform x:Name="PART_AnimationTransform" ScaleY="0" />
                            </Canvas.RenderTransform>
                        </Canvas>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
 
        <Style x:Key="CustomLabelStyle" TargetType="telerik:SeriesItemLabel">
            <Setter Property="HorizontalContentAlignment" Value="Center" />
            <Setter Property="Padding" Value="2,0" />
            <Setter Property="IsHitTestVisible" Value="False"/>
            <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="Transparent"
                                    Background="Transparent">
                                <TextBlock Foreground="White"
                                           TextAlignment="{TemplateBinding HorizontalContentAlignment}"
                                           Margin="0"
                                           Text="{TemplateBinding Content}" />
                            </Border>
                        </Canvas>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
 
        <Style x:Key="CustomLegendItemStyle" TargetType="telerik:ChartLegendItem">
            <Setter Property="Template" >
                <Setter.Value>
                    <ControlTemplate TargetType="telerik:ChartLegendItem">
                        <Grid x:Name="PART_MainContainer" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="0,0,5,0">
                            <Path x:Name="PART_LegendItemMarker"
                                  Height="20"
                                  Width="100"
                                  Style="{TemplateBinding ItemStyle}"
                                  Stretch="Fill">
                                <Path.Data>
                                    <PathGeometry x:Name="PART_ItemMarkerGeometry" />
                                </Path.Data>
                            </Path>
                            <CheckBox IsChecked="True"
                                      VerticalAlignment="Center"
                                      Margin="2,0"
                                      Content="{TemplateBinding Label}"
                                      Foreground="{TemplateBinding Foreground}"
                                      Command="{Binding Path=Data.ChangeSeriesVisibilityCommand, Source={StaticResource DataContext}}"
                                      CommandParameter="{TemplateBinding Label}"
                                      />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
 
        <!--<Style x:Name="AxisXStyle" TargetType="telerik:AxisX2D">
            <Setter Property="Template">
                <Setter.Value>
                     
                </Setter.Value>
            </Setter>
        </Style>-->
        <Style x:Key="AxisXTickStyle"
                TargetType="telerik:AxisX2D">
            <Setter Property="Foreground"
                Value="Orange" />
        </Style>
        <SolidColorBrush x:Key="ChartBackGround" Color="#E5000000"/>
 
 
    </UserControl.Resources>
    <Border telerikQuickStart:ThemeAwareBackgroundBehavior.IsEnabled="True">
        <telerik:RadChart x:Name="myReserveChart" ItemsSource="{Binding Source={StaticResource DataContext}, Path=Data}"
                          Height="350" VerticalAlignment="Center" AxisForeground="White" Background="{StaticResource ChartBackGround}"
                          BorderBrush="{StaticResource GridTransparentBackgroundBrush}" >
            <telerik:RadChart.SeriesMappings>
                <telerik:SeriesMapping LegendLabel="Price">
                    <telerik:SeriesMapping.SeriesDefinition >
                        <telerik:StepAreaSeriesDefinition ShowItemToolTips="False" ShowItemLabels="True" ShowPointMarks="False"
                                                         SeriesItemLabelStyle="{StaticResource CustomLabelStyle}"
                                                         ItemLabelFormat="$#Y/Hour" ItemToolTipFormat="Time: #XCAT -\nCosts: #Y/Hour"
                                                         Visibility="{Binding Source={StaticResource DataContext}, Path=Data.SeriesPriceVisibility}">
 
 
                            <telerik:StepAreaSeriesDefinition.Appearance>
                                <telerik:SeriesAppearanceSettings Fill="{StaticResource LegendItem1Background}" StrokeThickness="0">
                                    <telerik:SeriesAppearanceSettings.PointMark>
                                        <telerik:PointMarkAppearanceSettings Shape="Circle"/>
                                    </telerik:SeriesAppearanceSettings.PointMark>
                                </telerik:SeriesAppearanceSettings>
                            </telerik:StepAreaSeriesDefinition.Appearance>
                        </telerik:StepAreaSeriesDefinition>
                    </telerik:SeriesMapping.SeriesDefinition>
                    <telerik:ItemMapping FieldName="Data.Price" DataPointMember="YValue" />
                    <telerik:ItemMapping FieldName="Data.Time" DataPointMember="XCategory" />
                </telerik:SeriesMapping>
 
                <telerik:SeriesMapping LegendLabel="Available">
                    <telerik:SeriesMapping.SeriesDefinition>
                        <telerik:LineSeriesDefinition ShowItemLabels="False"
                                                      ShowItemToolTips="True" AxisName="AvailableAxis"
                                                      ItemToolTipFormat="Time: #XCAT{MM:dd:yyyy}\nAvailable: #Y"
                                                      Visibility="{Binding Source={StaticResource DataContext}, Path=Data.SeriesAvailableVisibility}">
                        </telerik:LineSeriesDefinition>
                    </telerik:SeriesMapping.SeriesDefinition>
                    <telerik:ItemMapping FieldName="Data.Available" DataPointMember="YValue" />
                    <telerik:ItemMapping FieldName="Data.Time" DataPointMember="XCategory" />
                </telerik:SeriesMapping>
            </telerik:RadChart.SeriesMappings>
             
            <telerik:RadChart.DefaultView>
                <telerik:ChartDefaultView ChartLegendPosition="Left">
                    <telerik:ChartDefaultView.ChartArea>
                        <telerik:ChartArea  NoDataString="Waiting for data..." >
                            <telerik:ChartArea.AxisX>
                                <telerik:AxisX DefaultLabelFormat="#VAL{hh:mm}" LabelRotationAngle="0" 
                                               LabelStep="2" IsDateTime="True"  LayoutMode="Inside" />
 
                            </telerik:ChartArea.AxisX>
                            <telerik:ChartArea.AxisY>
                                <telerik:AxisY  AutoRange="true" 
                                                   Visibility="Collapsed"
                                                   StripLinesVisibility="Collapsed"
                                                   MajorGridLinesVisibility="Collapsed" />
                            </telerik:ChartArea.AxisY>
                            <telerik:ChartArea.AdditionalYAxes>
                                <telerik:AxisY AxisName="AvailableAxis"
                                                   AutoRange="true"
                                                   Visibility="Collapsed"
                                                   StripLinesVisibility="Collapsed"
                                                   MajorGridLinesVisibility="Collapsed" />
                            </telerik:ChartArea.AdditionalYAxes>
                        </telerik:ChartArea>
                    </telerik:ChartDefaultView.ChartArea>
                    <telerik:ChartDefaultView.ChartLegend>
                        <telerik:ChartLegend />
 
                    </telerik:ChartDefaultView.ChartLegend>
                </telerik:ChartDefaultView>
            </telerik:RadChart.DefaultView>
 
        </telerik:RadChart>
    </Border>
</UserControl>

1 Answer, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 15 Mar 2011, 10:44 AM
Hello Li,

By default, the RadChart.DefaultView.ChartLegend is associated with the RadChart.DefaultView.ChartArea. When you predefine the DefaultView of the RadChart, the LegendName property of the ChartArea needs to be set to the name of the newly created ChartLegend. Otherwise, your legend items will not be auto generated. You can find more information about the RadChart Legend in our help topic.

Greetings,
Evgenia
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Chart
Asked by
Li
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Share this question
or