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

Pie Chart Problems (spider mode, connecter)

1 Answer 98 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Hello,

I use the following code, I created a pie chart that appears with label displayed in spider mode (SpiderModeEnabled = true). However, did not displayed label of "Foo". (image1.jpg)

MainWindow.xaml
<Window x:Class="Test.MainWindow"
        Title="MainWindow"
        Height="250"
        Width="495"
        xmlns:TelerikChart="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting"
        xmlns:TelerikCharting="clr-namespace:Telerik.Windows.Controls.Charting;assembly=Telerik.Windows.Controls.Charting">
    <Grid>
        <TelerikChart:RadChart x:Name="m_RadChart" />
    </Grid>
</Window>

MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.Charting;
using Telerik.Windows.Controls;
 
namespace Test
{
 
    // Data model.
    public class ChartRecord
    {
        public string Legend { get; set; }
 
        public int Value { get; set; }
    }
 
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
 
            // Create data source.
            List<ChartRecord> source = new List<ChartRecord>();
            source.Add(new ChartRecord() { Legend = "Foo", Value = 50 });
            source.Add(new ChartRecord() { Legend = "Bar", Value = 30 });
            source.Add(new ChartRecord() { Legend = "Baz", Value = 20 });
            m_RadChart.ItemsSource = source;
 
            m_RadChart.DefaultView.ChartArea.SmartLabelsEnabled = true;
 
            PieSeriesDefinition definition = new PieSeriesDefinition();
 
            // Setup label settings.
            RadialLabelSettings labelSettings = new RadialLabelSettings();
            labelSettings.SpiderModeEnabled = true;
            labelSettings.ShowConnectors = true;
            definition.LabelSettings = labelSettings;
             
            // Setup mappings.
            SeriesMapping seriesMapping = new SeriesMapping();
            seriesMapping.SeriesDefinition = definition;
            seriesMapping.ItemMappings.Add(new ItemMapping("Value", DataPointMember.YValue));
            seriesMapping.ItemMappings.Add(new ItemMapping("Legend", DataPointMember.XCategory));
            m_RadChart.SeriesMappings.Add(seriesMapping);
        }
    }
}

In addition, connecter disappeared when after making resize to small window until a pie chart disappears, restore to the original size.  (image2.jpg)

Do you have problem solution?

Thanks,

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 18 Nov 2011, 10:16 AM
Hi Hiroyuki Ishida,

In a scenario, like yours, where you have a relatively small height of the chart it would be better to set the SmartLabelsEnabled property to false and define a Distance value in the label settings, that would best suit the available space of the ChartArea. Please, consider the following code snippet : 
public MainWindow()
        {
            InitializeComponent();
  
            // Create data source.
            List<ChartRecord> source = new List<ChartRecord>();
            source.Add(new ChartRecord() { Legend = "Foo", Value = 50 });
            source.Add(new ChartRecord() { Legend = "Bar", Value = 30 });
            source.Add(new ChartRecord() { Legend = "Baz", Value = 20 });
            m_RadChart.ItemsSource = source;
   
            m_RadChart.DefaultView.ChartArea.SmartLabelsEnabled = false;
   
            PieSeriesDefinition definition = new PieSeriesDefinition();     
               
            // Setup mappings.
            SeriesMapping seriesMapping = new SeriesMapping();
            seriesMapping.SeriesDefinition = definition;
            m_RadChart.SeriesMappings.Add(seriesMapping);
            RadialLabelSettings labelSettings = new RadialLabelSettings();
            definition.LabelSettings = labelSettings;
            labelSettings.SpiderModeEnabled = true;
            labelSettings.ShowConnectors = true;
            labelSettings.Distance = 15;           
            seriesMapping.ItemMappings.Add(new ItemMapping("Value", DataPointMember.YValue));
            seriesMapping.ItemMappings.Add(new ItemMapping("Legend", DataPointMember.XCategory));          
        }

In this manner all labels of the Pie would be within the ChartArea and connectors would not disappear on resizinig of the window as well. The Distance property can be further adjusted to best fit the desired look of the chart. 

Greetings,
Nikolay
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Tags
Chart
Asked by
Answers by
Nikolay
Telerik team
Share this question
or