This is a migrated thread and some comments may be shown as answers.
rad chart title binding
9 Answers 93 Views
This is a migrated thread and some comments may be shown as answers.
rooma
Top achievements
Rank 1
rooma asked on 07 Oct 2011, 12:52 PM
Hello ,
I am trying to  bind my rad chart title to a string in view model.

 

 

<telerik:ChartDefaultView.ChartTitle>

 

 

<telerik:ChartTitle Content= "{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type views:PlotView}},Path=DataContext.ChartTitle}" HorizontalAlignment="Center"/>

 

 

</telerik:ChartDefaultView.ChartTitle>


But it is not getting binded niether i am getting any error.
Please help.....

9 Answers, 1 is accepted

Sort by
0
rooma
Top achievements
Rank 1
answered on 11 Oct 2011, 07:30 AM
Anyone please help................
0
Ves
Telerik team
answered on 12 Oct 2011, 09:55 AM
Hi Rooma,

Unfortunately, there is a problem with title content databinding. Please, find attached a small example with a suggestion for a workaround.

Regards,
Ves
the Telerik team

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

0
Nicholas
Top achievements
Rank 2
answered on 01 May 2012, 07:20 PM

Hi rooma,

I just spent way, way too long trying to sort this out.  I am incredulous that a WPF product has an issue with binding to the view model and it remains  unfixed.  Here is what I did to get around the problem after hours and hours of trying figure out what was wrong in my xaml.  It really never occurred to me that such basic functionality could be not  working. 

I subscribed to the DataBound event to wire up my ChartTitle:

<telerik:RadChart x:Name="scatterChart" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" DataBound="scatterChart_DataBound">

I gave a name to my ChartTitle

<telerik:ChartDefaultView.ChartTitle>

    <telerik:ChartTitle Content=""

                        x:Name="title"

                        HorizontalAlignment="Center"

                        Background="White"

                        Foreground="Black"

                         Visibility="Visible">

    </telerik:ChartTitle>

</telerik:ChartDefaultView.ChartTitle>


And I added the event handler in my code behind


private void scatterChart_DataBound(object sender, Telerik.Windows.Controls.Charting.
ChartDataBoundEventArgs e)

{

this.title.Content = ((ScatterChartViewModel)this.DataContext).ChartTitle;

}


I have a hard time grasping how this could not be corrected ASAP...  it is just such basic functionality.  This is a WPF product with a main GUI element that is not bindable to the view model in the xaml.  Outrageous!  It is not right!

Hope this helps.

Regards

0
Enrique Albert
Top achievements
Rank 1
answered on 27 Jun 2012, 11:02 AM
Hi,

I agree, we are assessing the Telerik WPF chart controls for a new commercial application and this sort of issue is a problem when considering the suite.

Can you indicate if a defect has been logged against this issue and if there is a fix available?

Thanks

EDIT (Work around using dependency property that provides dynamic binding -- which above two solutions do not provide)

I created a new class inheriting from RadChart:

 

    class NavitasRadChart
        :
RadChart
    {
        
public static readonly DependencyProperty ChartTitleProperty =
            
DependencyProperty.Register(
                
"ChartTitle",
                
typeof(string),
                
typeof(NavitasRadChart),
                
new PropertyMetadata(string.Empty, OnChartTitleChanged));
 
        
private static void OnChartTitleChanged(DependencyObject dependencyObject,
            
DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            
var chart = dependencyObject as NavitasRadChart;
            
if (chart == nullreturn;
            chart.Refresh();
        }
 
        
public string ChartTitle
        {
            
get { return (string) GetValue(ChartTitleProperty); }
            
set { SetValue(ChartTitleProperty, value); }
        }
 
        
private void Refresh()
        {
            DefaultView.ChartTitle.Content = ChartTitle;
        }
    }

 

So it contains a new 'ChartTitle' dependency property; when the property is changed it executes the new Refresh method that looks after the title content.

 

The XAML in the view can use a binding expression, so if the model changes the title also changes:

 

                <core:NavitasRadChart x:Name="radChart"                                  
                                 
 ...
                                 
 ChartTitle="{Binding Path=ChartTitleCaption}"
                                 
 >
                    ...
                </core:NavitasRadChart>

 

The 'core' namespace refers to the location of the new class, in my case:

xmlns:core="clr-namespace:Navitas.Client.Core"

 

0
Nicholas
Top achievements
Rank 2
answered on 27 Jun 2012, 03:52 PM
I do not know if "defect has been logged against this issue and if there is a fix available".

It is also surprising that  binding does not seem to be possible custom lines or marked zones. I was further surprised there seems to be no way to bind a collection of ranges.  It seems reasonable to expect more than one range.
0
Yavor
Telerik team
answered on 02 Jul 2012, 10:43 AM
Hello,

The issues you are observing are caused by the difference between objects used for configuration and visual objects that are added to the visual tree at run time. We have identified this problem and we are taking actions to prevent such problems in our new charting solution - the RadChartView. In the chart view we are using only visual objects that work well with bindings.

Please excuse us for the caused inconvenience!

All the best,
Yavor
the Telerik team

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

0
Nicholas
Top achievements
Rank 2
answered on 03 Jul 2012, 12:49 PM
Thanks for the follow up.  I tried out the RadChartView when it was Beta and I had to many issues, perhaps many from my own lack if experience even with the basics of .NET and WPF.  I had sort of forgotten about RadChartView but I think I will try it out again in hope of leveraging the more robust binding.  The charting requirements here are very complex and I am pushing the limits of RadChart. 

Regards
0
Nicholas
Top achievements
Rank 2
answered on 03 Jul 2012, 01:33 PM
Checked out RadChartView at seems it does not yet support all the feature required here (range series, custom lines, marked zones) and I can see no information on how to combine charts of different types.  Regardless, thanks for the follow up!
0
Yavor
Telerik team
answered on 06 Jul 2012, 08:25 AM
Hi Nicholas,

Custom lines and marked zones are currently under development and will be available with the Q3 release. Range series are also planned for the upcoming releases.

You can check this demo here that demonstrates how you can combine series. You can also combine series of different types using the same technique.

All the best,
Yavor
the Telerik team

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

Tags
Chart
Asked by
rooma
Top achievements
Rank 1
Answers by
rooma
Top achievements
Rank 1
Ves
Telerik team
Nicholas
Top achievements
Rank 2
Enrique Albert
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or