Is it possible to assign One series lable to onther series in the same chart?

2 posts, 0 answers
  1. Chinmaya
    Chinmaya avatar
    24 posts
    Member since:
    Aug 2014

    Posted 17 Oct 2014 Link to this post

    I have a Bar series to show number of parts produced at the same time i would like to show percentage of yield produced by that line.

    here is what i tried

                    var labelDefinition=new ChartSeriesLabelDefinition();
                    labelDefinition.Template = App.Current.Resources["LabelTemplateString"] as DataTemplate;               
                    BarSeries okSeries = new BarSeries();
                    okSeries.ItemsSource = this.yields;
                    okSeries.CategoryBinding = new PropertyNameDataPointBinding() { PropertyName = "LocationName" };
                    okSeries.ValueBinding = new GenericDataPointBinding<Yield, int>() { ValueSelector = yield => yield.OK };
                    okSeries.CombineMode = ChartSeriesCombineMode.Stack;
                    okSeries.DefaultVisualStyle = App.Current.Resources["YieldOK"] as Style;
                    okSeries.ShowLabels = true;
                    BarSeries nokSeries = new BarSeries();
                    nokSeries.ItemsSource = this.yields;
                    nokSeries.CategoryBinding = new PropertyNameDataPointBinding() { PropertyName = "LocationName" };
                    nokSeries.ValueBinding = new GenericDataPointBinding<Yield, int>() { ValueSelector = yield => yield.NOK };
                    nokSeries.CombineMode = ChartSeriesCombineMode.Stack;
                    nokSeries.DefaultVisualStyle = App.Current.Resources["YieldNOK"] as Style;
                    PointSeries percentSeries = new PointSeries();
                    percentSeries.ItemsSource = this.yields;             
                    percentSeries.CategoryBinding = new PropertyNameDataPointBinding() { PropertyName = "LocationName" };
                    percentSeries.ValueBinding = new PropertyNameDataPointBinding("Percent");                
                    percentSeries.PointTemplate = App.Current.Resources["PointTemplateBlue"] as DataTemplate;                
                    percentSeries.ShowLabels = true;       

    <DataTemplate x:Key="LabelTemplateString">
                    <TextBlock Text="{Binding Path=DataItem.Percent }"  FontSize="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=local:YieldChart}, Path=PercentSize}"/>

  2. Petar Marchev
    Petar Marchev avatar
    968 posts

    Posted 21 Oct 2014 Link to this post

    Hi Chinmaya,

    I have attached a simple project that demonstrates how to get this working. A label template is used (similar to your label template). You can see that as long as the underlying business item has a Percent property - the Percent is displayed in the label. Do run the project and see if you get the same behavior on your side. Then you can see what are the differences between the attached project and your actual application.

    I see that you are using a relative source binding. Due to the layout logic of the chart, such a binding is not expected to work and will result in an incorrectly positioned label. I suggest you remove this and use another approach.

    Let us know how it goes and if you need more information. If you need further assistance, please modify the attachment and send it back to us so that we can start looking for solutions.

    Petar Marchev

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  3. DevCraft R3 2016 release webinar banner
Back to Top