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

Binding xaml to DataSeries

2 Answers 56 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Mathew Tonsager
Top achievements
Rank 1
Mathew Tonsager asked on 08 Apr 2010, 01:20 PM
Hello,

I would like to thank you in advance for reading this!

Is there a way to bind the DataSeries data to a property when customizing a BarSeries/LineSeries style?

I know you can do this if the data is set at the ItemSource level, but what about the DataSeries level?

Ex:

<Style x:Key="BarSeriesStyle" TargetType="telerikCharting:Bar">  
        <Setter Property="Template">  
            <Setter.Value> 
                <ControlTemplate TargetType="telerikCharting:Bar">  
                    <Canvas> 
                        <Rectangle x:Name="PART_DefiningGeometry" 
                              Height="{TemplateBinding ItemActualHeight}" 
                              Width="{TemplateBinding ItemActualWidth}" 
                              RadiusX="2" 
                              RadiusY="2" 
                              Fill="Pink" 
                              Stroke="{Binding DataItem.GradeColor}" 
                              StrokeThickness="3"  /> 
                    </Canvas> 
                    <ControlTemplate.Triggers> 
                        <Trigger Property="IsMouseOver" Value="true">  
                            <Setter TargetName="PART_DefiningGeometry" Property="Fill" Value="{StaticResource LightBrush}"/>  
                            <Setter TargetName="PART_DefiningGeometry" Property="Stroke" Value="{StaticResource LightBrush}"/>  
                            <!--<Setter TargetName="Border" Property="SnapsToDevicePixels" Value="true"/>--> 
                        </Trigger> 
                    </ControlTemplate.Triggers> 
                </ControlTemplate> 
            </Setter.Value> 
        </Setter> 
    </Style> 

Notice the line Stroke="{Binding DataItem.GradeColor}" 

How would I bind this to a DataSeries set of information as opposed to the ItemSource set of information?

Thanks,
Matt

2 Answers, 1 is accepted

Sort by
0
Mathew Tonsager
Top achievements
Rank 1
answered on 08 Apr 2010, 02:51 PM

Hi again,

I think I have figured out why the (Stroke="{Binding DataItem.GradeColor}") binding is not working. The DataItem is not being set when I add the DataSeries using VB code.

I am trying to add a DataSeries manually in code like this:

Dim ds As New DataSeries()  
        ds.Definition = New BarSeriesDefinition()  
        For Each person As Person In studentList  
            ds.Add(New DataPoint(person.Name, person.Grade))  
        Next 

Then add the DataSeries to the RadChart like this:

RadChart1.DefaultView.ChartArea.DataSeries.Add(ds) 

    
So, naturally my binding won't work because my DataItem is not set for the DataSeries.

See attached picture!

How do I set the DataItem in VB for each DataSeries I create?

Thanks,
Matt

0
Vladimir Milev
Telerik team
answered on 14 Apr 2010, 09:37 AM
Hi Mathew Tonsager,

Simply set the DataItem property to the instance of your DataPoint to the data object you require.

Kind regards,
Vladimir Milev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Chart
Asked by
Mathew Tonsager
Top achievements
Rank 1
Answers by
Mathew Tonsager
Top achievements
Rank 1
Vladimir Milev
Telerik team
Share this question
or