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

Getting color series

2 Answers 61 Views
Chart
This is a migrated thread and some comments may be shown as answers.
david
Top achievements
Rank 1
david asked on 29 Aug 2013, 11:22 AM
Hello,

I have a radchart and personalized chartlegend. In my chartlegend I have a checkbox and I need to get the color that has given radchart sets. But when I try to know the color, in "aparrence" fields appear all to null, but really if you are painting with a certain color.

<telerik:RadChart x:Name="RadChart1"
                  Grid.Row="1"
                  Grid.Column="1"
                  UseDefaultLayout="False">
    <telerik:RadChart.SamplingSettings>
        <telerik:SamplingSettings SamplingFunction="Average" />
    </telerik:RadChart.SamplingSettings>
 
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="10" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="10" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="10" />
            <RowDefinition Height="*" />
            <RowDefinition Height="100" />
            <RowDefinition Height="10" />
        </Grid.RowDefinitions>
        <Grid />
        <telerik:ChartLegend x:Name="legendChart"
                             Grid.Row="2"
                             Grid.Column="1"
                             Header=""
                             ItemContainerStyle="{DynamicResource CharLegendStyle}"
                             ItemsPanelOrientation="Horizontal"
                             LegendItemMarkerShape="Circle"
                             UseAutoGeneratedItems="false" />
 
        <telerik:ChartArea x:Name="lineGraphChartArea"
                           Grid.Row="1"
                           Grid.Column="1"
                           HorizontalAlignment="Stretch"
                           VerticalAlignment="Stretch"
                           EnableAnimations="False"
                           LegendName="legendChart">
            <telerik:ChartArea.AxisX>
                <telerik:AxisX Title="Fecha"
                               AutoRange="True"
                               IsDateTime="True"
                               Step="1" />
            </telerik:ChartArea.AxisX>
            <telerik:ChartArea.AxisY>
                <telerik:AxisY Title="CMN"
                               AutoRange="True"
                               ExtendDirection="Up"
                               IsZeroBased="True" />
            </telerik:ChartArea.AxisY>
 
 
        </telerik:ChartArea>
 
    </Grid>
 
 
</telerik:RadChart>


public SeriesMapping GenerateRandomSeries(string nameSerie,int begin)
        {
            SeriesMapping serie1 = new SeriesMapping();
            serie1.ItemsSource = GenerateRandomData(begin);
            serie1.ChartAreaName = "lineGraphChartArea";
            serie1.LegendLabel = nameSerie;
            ItemMapping X = new ItemMapping("Fecha", DataPointMember.XValue);
            ItemMapping Y = new ItemMapping("CMN", DataPointMember.YValue);
            serie1.ItemMappings.Add(X);
            serie1.ItemMappings.Add(Y);
 
            serie1.SeriesDefinition = new SplineSeriesDefinition()
                {
                    
                };
            
             
 
            return serie1;
 
        }
 
public void AddSerieDefinition()
        {
 
 
            RadChart1.SeriesMappings.Add(GenerateRandomSeries("serie1",5));
            RadChart1.SeriesMappings.Add(GenerateRandomSeries("serie2",10));
            RadChart1.SeriesMappings.Add(GenerateRandomSeries("serie3",15));
        }


I try get color and (look attached)


Thank you!

2 Answers, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 03 Sep 2013, 08:05 AM
Hi David,

  Unfortunately, there is no easy way to extract the colors of the visual series and use it to manually generate legend items. There are two workarounds though that you may choose from:
1. You can set the color of your series using the appearance API exposed by the SeriesDefinition object and set exactly the same color to the legend item for each visual series.Here is a sample code demonstrating how to use the appearance API:

ISeriesDefinition def = new LineSeriesDefinition();
def.Appearance.Fill = new SolidColorBrush(Colors.Yellow);
def.Appearance.Foreground = new SolidColorBrush(Colors.Green);
def.Appearance.Stroke = new SolidColorBrush(Colors.White);

2. You might create your own custom Palette and apply it to the Chart as shown in our documentation. When the underlying data is changed, you can add/remove/alter the palette brushes accordingly, in order to preserve the logical correlation between some serie and its corresponding Color. Check this online example with source code provided where you will see how we keep the relation between a color and series because when a series is not visible (the corresponding checkbox is unchecked), it is actually hidden. Please mind that even though the example is made under Silverlight, the code is practically the same for WPF.

Regards,
Evgenia
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
david
Top achievements
Rank 1
answered on 03 Sep 2013, 08:39 AM
Thank you!!
Tags
Chart
Asked by
david
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
david
Top achievements
Rank 1
Share this question
or