Color columns in bar chart with global pallete

4 posts, 0 answers
  1. Oleg
    Oleg avatar
    10 posts
    Member since:
    Aug 2012

    Posted 09 Sep 2013 Link to this post

    Hi, according to sample, i am coloring columns using DataTemplate. At the same page, i use the same colors to color Pie chart, there they are defined in the global pallete. Is there any change to use one declaration of colors to avoid copy-paste?
    <Grid Grid.Row="1">
        <Grid.Resources>
            <telerikChart:ChartPalette x:Key="paletteEntryCollection">
                <telerikChart:ChartPalette.GlobalEntries>
                    <telerikChart:PaletteEntry Fill="#207098" Stroke="{StaticResource PhoneForegroundBrush}" />
                </telerikChart:ChartPalette.GlobalEntries>
            </telerikChart:ChartPalette>
        </Grid.Resources>
             
        <telerikChart:RadCartesianChart Name="BarChart"
                                        Palette="{StaticResource paletteEntryCollection}" >             
     
            <telerikChart:RadCartesianChart.HorizontalAxis>
                <telerikChart:LinearAxis ShowLabels="False" />
            </telerikChart:RadCartesianChart.HorizontalAxis>
            <telerikChart:RadCartesianChart.VerticalAxis >
                <telerikChart:CategoricalAxis>
                    <telerikChart:CategoricalAxis.LabelStyle>
                        <Style TargetType="TextBlock">
                            <Setter Property="FontSize" Value="20" />
                        </Style>
                    </telerikChart:CategoricalAxis.LabelStyle>
                </telerikChart:CategoricalAxis>
            </telerikChart:RadCartesianChart.VerticalAxis>
                     
            <telerikChart:BarSeries ShowLabels="True" ValueBinding="Value" CategoryBinding="Category">
                <telerikChart:BarSeries.PointTemplates>
                    <DataTemplate>
                        <Rectangle Fill="#207098"/>
                    </DataTemplate>
                </telerikChart:BarSeries.PointTemplates>
            </telerikChart:BarSeries>
        </telerikChart:RadCartesianChart>
    </Grid>
     
  2. Deyan
    Admin
    Deyan avatar
    2039 posts

    Posted 12 Sep 2013 Link to this post

    Hi Oleg,

    Thanks for writing.

    As far as I understand the scenario, you may try to additionally define the colors as static resources in the Grid's resource dictionary and reference them when needed?

    Regards,
    Deyan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINDOWS PHONE 7.
    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 >>
  3. DevCraft banner
  4. Oleg
    Oleg avatar
    10 posts
    Member since:
    Aug 2012

    Posted 15 Sep 2013 Link to this post

    Yes i can, then i will have the same colors two times - in chart pallete and in datapoints templates
  5. Rosy Topchiyska
    Admin
    Rosy Topchiyska avatar
    551 posts

    Posted 18 Sep 2013 Link to this post

    Hi Oleg,

    You can use a value converter when setting the Fill property of the Rectangle in the  template to get the index of the corresponding DataPoint and convert it to a PaletteEntry. I have attached a sample runnable application that demonstrates how this can be achieved in practice.

    I hope this helps. Please, do not hesitate to contact us if there is anything else we can assist you with.

    Regards,

    Rositsa Topchiyska
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINDOWS PHONE 7.
    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 >>
Back to Top