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

Binding entity to the command parameter in RadCartesianChart

1 Answer 95 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Tommi
Top achievements
Rank 1
Tommi asked on 11 Jul 2014, 11:38 AM
Hello,
I would like to bind entity from the itemsource collection to the command parameter.

My goal is to open certain entity when it is clicked from the grid, but have unable to bind
the entity from the binded collection.

Is this possible to do by using MVVM approach?
One challenge is that I have two telerik:BarSeries defined for the chart.

So this code line at the below needs to be sorted out,
"CommandParameter="???????????????" 

Here is the full code:


<telerik:RadCartesianChart Margin="10" IsHitTestVisible="True">

           <telerik:RadCartesianChart.Grid>
                <telerik:CartesianChartGrid MajorLinesVisibility="XY" MajorXLinesRenderMode="All">
                </telerik:CartesianChartGrid>
           </telerik:RadCartesianChart.Grid>

            <telerik:RadCartesianChart.HorizontalAxis>
                <telerik:DateTimeContinuousAxis MajorStepUnit="Minute" MajorTickStyle="{StaticResource MajorTickStyle}" PlotMode="OnTicksPadded">
                    <telerik:DateTimeContinuousAxis.TitleTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding}"></TextBlock>
                        </DataTemplate>
                    </telerik:DateTimeContinuousAxis.TitleTemplate>
                </telerik:DateTimeContinuousAxis>
            </telerik:RadCartesianChart.HorizontalAxis>
            
            <telerik:RadCartesianChart.VerticalAxis>
                <telerik:LinearAxis Minimum="0" Maximum="200" ShowLabels="False"></telerik:LinearAxis>
            </telerik:RadCartesianChart.VerticalAxis>

            <telerik:BarSeries ItemsSource="{Binding EntityData1}" ValueBinding="EntityTime" CategoryBinding="EntityTakingTime" Height="1000">
                <telerik:BarSeries.PointTemplate>
                    <DataTemplate>
                        <Rectangle x:Name="RectangleGreen" Fill="Green" MaxWidth="20"/>
                    </DataTemplate>
                </telerik:BarSeries.PointTemplate>
            </telerik:BarSeries>

            <telerik:BarSeries ItemsSource="{Binding EntityData2}" ValueBinding="EntityTime" CategoryBinding="EntityTakingTime" Height="1000">
                <telerik:BarSeries.PointTemplate>
                    <DataTemplate>
                        <Rectangle x:Name="RectangleRed" Fill="Red" MaxWidth="20"/>
                    </DataTemplate>
                </telerik:BarSeries.PointTemplate>
            </telerik:BarSeries>

           <telerik:EventToCommandBehavior.EventBindings>
                <telerik:EventBinding Command="{Binding OpenEntityCommand}" 
                                      EventName="MouseLeftButtonDown" 
                                      RaiseOnHandledEvents="True"
                                      CommandParameter="???????????????" />
            </telerik:EventToCommandBehavior.EventBindings>

</telerik:RadCartesianChart>


Check the attached screenshot to see the generated chart.
Green and red bars should work as links to open certain entity.

Best Regards, Tommi







1 Answer, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 14 Jul 2014, 08:35 AM
Hi Tommi,

The wpf framework does not allow a binding in the CommandParameter because the Binding object is not a DependencyObject and the CommandParameter property is not a DependencyProperty. Perhaps you can simply attach an event handler to the MouseLeftButtonDown event of the series, set the IsHitTestVisible property of the series to true and in the event handler get the original source, get its data context (which is a DataPoint) and get the DataItem (which is the actual business item). Let us know how it goes.

Regards,
Petar Marchev
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
Chart
Asked by
Tommi
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Share this question
or