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

Polar Chart refresh LabelTemplateSelector

5 Answers 44 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Daniela
Top achievements
Rank 1
Daniela asked on 26 Jul 2013, 08:14 AM
Hi!
I have a problem with the LabelTemplateSelector on the RadPolarChart.
I define the TemplateSelector for the items and the first time it is loaded everything works fine. Depending on the properties of the item I deside which template is returned (e.g. the property value is greater than 0 I return another template than if the value is 0).

 When I change the series (I have a dropdown to select the items source which should be displayed in the polar chart) the LabelTemplateSelector is not called again. So, the template style of the labels is not up to date. How can I force the LabelTemplateSelector to be recalled?

Here is the definition of my polar chart:
<telerik:RadPolarChart x:Name="_polarChart"
Grid.Row="0"
Grid.RowSpan="2"
IsEnabled="{Binding IsActiveSubstanceLoaded}"
Visibility="Collapsed">
                                <telerik:RadPolarChart.Grid>
                                    <telerik:PolarChartGrid GridLineVisibility="Both" StripesVisibility="Both">
                                        <telerik:PolarChartGrid.RadialStripeBrushes >
                                            <SolidColorBrush Color="Green" />
                                            <SolidColorBrush Color="Gold" />
                                            <SolidColorBrush Color="DarkOrange" />
                                            <SolidColorBrush Color="Firebrick" />
                                        </telerik:PolarChartGrid.RadialStripeBrushes>
                                    </telerik:PolarChartGrid>
                                </telerik:RadPolarChart.Grid>
                                <telerik:RadPolarChart.RadialAxis>
                                    <telerik:CategoricalRadialAxis LineStroke="Transparent" LabelTemplateSelector="{StaticResource MyRadPolarChartTemplateSelector}" />
                                </telerik:RadPolarChart.RadialAxis>
                                <telerik:RadPolarChart.PolarAxis>
                                    <telerik:PolarAxis FontWeight="Bold" TickThickness="3" Minimum="0" Maximum="4" MajorStep="1" LineStroke="Transparent" />
                                </telerik:RadPolarChart.PolarAxis>
                                <telerik:RadPolarChart.Behaviors>
                                    <telerik:ChartTooltipBehavior Placement="Top" VerticalOffset="10" />
                                </telerik:RadPolarChart.Behaviors>
                                <telerik:RadPolarChart.TooltipTemplate>
                                    <DataTemplate>
                                        <Grid>
                                            <Rectangle Stretch="Fill" Fill="Beige" Stroke="Black" />
                                            <StackPanel Margin="5,5,5,5">
                                                <StackPanel Orientation="Horizontal">
                                                    <TextBlock Loaded="tooltipTextBlock_Loaded"/>
                                                </StackPanel>
                                            </StackPanel>
                                        </Grid>
                                    </DataTemplate>
                                </telerik:RadPolarChart.TooltipTemplate>
                            </telerik:RadPolarChart>
This is the code which is called when the chart gets a new series:

private void createCharts()
{
    if (_polarChart != null)
    {
        _polarChart.Series.Clear();
 
        List<RiskViewModel> currentDataPoints = _mainViewModel.AllRiskViewModels.Where(risk => risk.IsCurrent && risk.Region == _mainViewModel.SelectedRegion).ToList();
        List<RiskViewModel> futureDataPoints = _mainViewModel.AllRiskViewModels.Where(risk => risk.IsFuture && risk.Region == _mainViewModel.SelectedRegion).ToList();
 
        if (currentDataPoints.Count() == 0 && futureDataPoints.Count() == 0)
        {
            _polarChart.Visibility = Visibility.Collapsed;
            _tbx_noDataFound.Visibility = Visibility.Visible;
            return;
        }
        else
        {
            _polarChart.Visibility = Visibility.Visible;
            _tbx_noDataFound.Visibility = Visibility.Collapsed;
        }
 
        if (currentDataPoints.Count() > 0 && cbxCurrent.IsChecked.Value)
        {
            RadarLineSeries series = generateSeries(currentDataPoints, this.Resources["SeriesCurrentColor"] as SolidColorBrush);
            series.Stroke = this.Resources["SeriesCurrentColor"] as SolidColorBrush;
            _polarChart.Series.Add(series);
             
        }
 
        if (futureDataPoints.Count() > 0 && cbxFuture.IsChecked.Value)
        {
            RadarLineSeries series = generateSeries(futureDataPoints, this.Resources["SeriesFutureColor"] as SolidColorBrush);
            series.Stroke = this.Resources["SeriesFutureColor"] as SolidColorBrush;
            _polarChart.Series.Add(series);
        }
    }
}
 
private RadarLineSeries generateSeries(List<RiskViewModel> dataPoints, SolidColorBrush color)
{
    RadarLineSeries series = new RadarLineSeries();
    series.ItemsSource = dataPoints;
    series.CategoryBinding = new PropertyNameDataPointBinding("Category");
    series.ValueBinding = new PropertyNameDataPointBinding("Score");
    series.PointTemplate = createDataPointTemplate(color);
    return series;
}

5 Answers, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 31 Jul 2013, 08:15 AM
Hi Daniela,

I am a bit confused here. The only TemplateSelector, shown in your code is set to the RadialAxis, which is categorical by nature and its labels can hold anything -- in this case it is Category. In case you need to set TemplateSelector for the series item labels, you will need to define a ChartSeriesLabelDefinition, configure the TemplateSelector for it, add it to LabelDefinitions collection of the series.

Best regards,
Ves
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Aaron
Top achievements
Rank 1
answered on 31 Jul 2013, 01:52 PM
Thanks for your response. Daniela works with me on this project and I tried to implement your solution by adding a ChartSeriesLabelDefinition to the RadarLineSeries. Unfortunately it did not work.

Here is what we did:
<telerik:RadPolarChart x:Name="_polarChart" >
    <telerik:RadPolarChart.Grid>
        <telerik:PolarChartGrid GridLineVisibility="Both" StripesVisibility="Both" >
            <telerik:PolarChartGrid.RadialStripeBrushes >
                <SolidColorBrush Color="Green" />
                <SolidColorBrush Color="Gold" />
                <SolidColorBrush Color="DarkOrange" />
                <SolidColorBrush Color="Firebrick" />
            </telerik:PolarChartGrid.RadialStripeBrushes>
        </telerik:PolarChartGrid>
    </telerik:RadPolarChart.Grid>
    <telerik:RadPolarChart.RadialAxis>
        <telerik:CategoricalRadialAxis LineStroke="Transparent" />
    </telerik:RadPolarChart.RadialAxis>
    <telerik:RadPolarChart.PolarAxis>
        <telerik:PolarAxis FontWeight="Bold" TickThickness="3" Minimum="0" Maximum="4" MajorStep="1" LineStroke="Transparent" />
    </telerik:RadPolarChart.PolarAxis>
    <telerik:RadarLineSeries>
        <telerik:RadarLineSeries.LabelDefinitions>
            <telerik:ChartSeriesLabelDefinition TemplateSelector="{StaticResource MyRadPolarChartTemplateSelector}" />
        </telerik:RadarLineSeries.LabelDefinitions>
    </telerik:RadarLineSeries>
</telerik:RadPolarChart>

The TemplateSelector is defined as follows:
<Style x:Key="RadarAxisLabelStyle" TargetType="TextBlock">
    <Setter Property="Width" Value="70" />
    <Setter Property="FontSize" Value="9.5" />
    <Setter Property="TextWrapping" Value="Wrap" />
</Style>
 
<local:LabelTemplateSelector x:Key="MyRadPolarChartTemplateSelector" >
    <local:LabelTemplateSelector.DefaultCategoryTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding}" Style="{StaticResource RadarAxisLabelStyle}" Margin="5" ecodat:ContextMenuHelper.EnableContextMenu="True"/>
        </DataTemplate>
    </local:LabelTemplateSelector.DefaultCategoryTemplate>
    <local:LabelTemplateSelector.BoldCategoryTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding}" Style="{StaticResource RadarAxisLabelStyle}" Margin="5" FontWeight="Bold" Foreground="DarkGreen" ecodat:ContextMenuHelper.EnableContextMenu="True"/>
        </DataTemplate>
    </local:LabelTemplateSelector.BoldCategoryTemplate>
</local:LabelTemplateSelector>

The SelectTemplate method from LabelTemplateSelector is never called:
public class LabelTemplateSelector : DataTemplateSelector
    {
    //...
        public override DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
        {
            // ... get model
            if (model.Workarea == BOLD_CATEGORY)
            {
                return BoldCategoryTemplate;
            }
            else
            {
                return DefaultCategoryTemplate;
            }
        }
    //...
    }

So is this what you meant?

One more question:
We used Silverlight 4 and RadControls Q3 2011 recently. This week we updated to Silverlight 5 and RadControls Q1 2013. Everything works fine but our customized RadialStripeBrushes are not shown anymore (polarchart_silverlight5.png). The default light-green/white background is visible instead. I attached a screenshot of the state before the update (polarchart.png). You can see the colored stripes and the working TemplateSelector (defined within the CategoricalRadialAxis).
Is it still possible to customize these stripes?

Thanks for your help!
0
Ves
Telerik team
answered on 05 Aug 2013, 12:05 PM
Hi Aaron,

I have attached a small example, which shows LabelTemplateSelector for RadarLineSeries in action. Note, that in the code snippets provided by Daniela, the series are cleared and then created again, so you will need to create the ChartSeriesLabelDefinition and the LabelTemplateSelector in code and assign them to the series.

As for the radial stripe brushes, I am afraid this is a bug in the control. I have logged it in our Public Issue Tracking System, you can follow it here. Our developers are already on it, so the fix will be available in one of the next internal builds and in 2013 Q3 release.

 I have updated your Telerik points for reporting this. Please, accept our apologies for the inconvenience.

Best regards,
Ves
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Aaron
Top achievements
Rank 1
answered on 05 Aug 2013, 12:21 PM
Thanks for your response and the solution you provided.

Regarding the RadialStripeBrushes: is there a possible workaround for this issue?
Since our customer (and our enterprise) does not intend to update the Telerik RadControls again until next year or so this bug might present a problem.
0
Accepted
Ves
Telerik team
answered on 08 Aug 2013, 11:51 AM
Hi Aaron,

Well, I guess you will have to mark this as a <not-pretty> workaround, but still there is one. As long as you are not using the PolarStripeBrushes, you can populate this collection with the same values and set StripLinesVisibility="Radial". The PolarChartGrid will draw radial stripes, using the same brushes.

Best regards,
Ves
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
ChartView
Asked by
Daniela
Top achievements
Rank 1
Answers by
Ves
Telerik team
Aaron
Top achievements
Rank 1
Share this question
or