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

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

1 Answer 17 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Chinmaya
Top achievements
Rank 1
Chinmaya asked on 17 Oct 2014, 10:23 AM
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.VerticalAlignment=VerticalAlignment.Bottom;               
                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.LabelDefinitions.Add(labelDefinition);
                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.LabelDefinitions.Add(labelDefinition);                
                percentSeries.ShowLabels = true;       

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


        

1 Answer, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 21 Oct 2014, 08:22 AM
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.

Regards,
Petar Marchev
Telerik
 

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.

 
Tags
ChartView
Asked by
Chinmaya
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Share this question
or