Setting stacked bar color

4 posts, 1 answers
  1. JR
    JR avatar
    7 posts
    Member since:
    Apr 2009

    Posted 02 Oct 2010 Link to this post

    Hi,

        I have a staked bar that i would want to set the color of each series base from the value passed to it. For example, for the series definition of a Stacked bar Chart below, say i would like to make the bar for seriesMapping and seriesMapping2 go red if the value of the two series goes below 5 and go green if the value is 5 and over. Note that they're independent meaning seriesMapping can be red while seriesMapping2 is green.
               

                SeriesMapping seriesMapping = new SeriesMapping();
                seriesMapping.SeriesDefinition = new StackedBarSeriesDefinition();
                seriesMapping.SeriesDefinition.ShowItemToolTips = false;
                ItemMapping itemMapping = new ItemMapping();
                itemMapping.DataPointMember = DataPointMember.YValue;
                itemMapping.FieldName = "MyValue1"; 

                seriesMapping.ItemMappings.Add(itemMapping);

                SeriesMapping seriesMapping2 = new SeriesMapping();
                seriesMapping2.SeriesDefinition = new StackedBarSeriesDefinition();
                seriesMapping2.SeriesDefinition.ShowItemToolTips = false;
                seriesMapping2.ItemMappings.Add(new ItemMapping("MyValue2", DataPointMember.YValue));
               
                SeriesMappingCollection map = new SeriesMappingCollection();
                map.Add(seriesMapping);
                map.Add(seriesMapping2);
                MyChart.SeriesMappings.AddRange(map);

  2. JR
    JR avatar
    7 posts
    Member since:
    Apr 2009

    Posted 03 Oct 2010 Link to this post

    Does anyone have an idea on my inquiry?
  3. Answer
    Fredrik
    Fredrik avatar
    54 posts
    Member since:
    Sep 2010

    Posted 04 Oct 2010 Link to this post

    Hello !!

    Not an expert on this but I had a simular problem that I solved with this http://www.telerik.com/help/silverlight/radchart-how-to-mvvm-support.html .

    Hope the link helps

    Regards

    Fredrik
  4. JR
    JR avatar
    7 posts
    Member since:
    Apr 2009

    Posted 04 Oct 2010 Link to this post

    Hi Fredrik, 

        That is one way to implement the update base on the some of the sites i've also visited but since im using an old version of the control i dont have the CreateItemStyleDelegate. As a result we just made 2 templates, one for the Bar of the first series and a second one for the second series, and just bind a member of the class to the template. Below is the part of the template with the binding.

    Section of the template: 
                                  ....
                                      <Rectangle x:Name="PART_DefiningGeometry"
                                        Height="{TemplateBinding ItemActualWidth}"
                                        Width="{TemplateBinding ItemActualHeight}"
                                        Fill="{Binding DataItem.BarColor2}"  //BarColor2 is the member of my class binded to the Chart
                                        Stroke="Black"
                                        Canvas.Top="{TemplateBinding ItemActualHeight}" >
                                    <Rectangle.RenderTransform>
                                        <TransformGroup>
                                            <RotateTransform Angle="-90"/>
                                            <TranslateTransform/>
                                        </TransformGroup>
                                    </Rectangle.RenderTransform>
                                </Rectangle>
                                  ....

    Then set the style to the series mapping.

            seriesMapping.SeriesDefinition = new StackedBarSeriesDefinition() { ItemStyle = Application.Current.Resources["ChartBarStyle2"] as Style };

    Marking your reply as the answer since yours is the much cleaner way to implement this. Thanks for the reply appreciate it. :)
Back to Top