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

Set bar chart label via code

1 Answer 107 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
DMM
Top achievements
Rank 1
DMM asked on 15 Jun 2012, 07:58 PM
BarSeries series = new BarSeries();                 
series.CategoryBinding = new PropertyNameDataPointBinding() { PropertyName = "Name" };                 
series.ValueBinding = new PropertyNameDataPointBinding() { PropertyName = "Value" };                 
series.ShowLabels = true;                 
series.ItemsSource = points;

My ItemsSource is just a list of my datapoint class.
How do I set the label for each point?
I can do it via xaml easy enough. How about code?


<telerik:CategoricalDataPoint Category="1" Value="0.05" Label="Some Point Specific Text"> 


I tried and failed with
             <telerik:BarSeries.LabelDefinitions > 
                    <telerik:ChartSeriesLabelDefinition >
                        <telerik:ChartSeriesLabelDefinition.Template>
                            <DataTemplate>
                                <StackPanel>
                                    <TextBlock Text="{Binding}"></TextBlock>
                                    <TextBlock>
                                    <TextBlock.Text>
                                         <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type telerik:BarSeries}}" 
                                                    Path
="DataPoints[0].DataItem.MyLabelProp"/>
                                    </TextBlock.Text>
                                    </TextBlock>
                               </StackPanel>
                            </DataTemplate>
                        </telerik:ChartSeriesLabelDefinition.Template>
                     </telerik:ChartSeriesLabelDefinition>
                </telerik:BarSeries.LabelDefinitions>

1 Answer, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 19 Jun 2012, 10:33 AM
Hi David,

Currently it is not possible to have access to the DataItem from the label template. I have discussed this with our developers and we think that it will be of great help to have access to both the value and the data item. This is why I have logged this as a feature request here in our PITS where you can vote for the feature and track its status.

We are sorry for the inconvenience. I have updated your Telerik points as a thank you for pointing this issue to us and helping us improve our products.

Regards,
Petar Marchev
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

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