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

[Solved] how to select Single?

3 Answers 145 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
ji
Top achievements
Rank 1
ji asked on 29 Dec 2010, 03:58 AM
<telerik:ChartArea x:Name="chart"
                 Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
              ItemClick="chartDianZong_ItemClick" />
//----------------
DataSeries barSeries = GetData();
            barSeries.Definition.InteractivitySettings.HoverScope = InteractivityScope.Item;
            barSeries.Definition.InteractivitySettings.SelectionScope = InteractivityScope.Item;
            barSeries.Definition.InteractivitySettings.SelectionMode = ChartSelectionMode.Single;

            barSeries.Definition.ShowItemToolTips = true;

            chart.DataSeries.Add(barSeries);

            chart.AxisY.Title = "";
            chart.AxisY.AxisStyles.TitleStyle = Resources["CustomAxisTitleStyle"] as Style;
            chart.AxisY.ExtendDirection = AxisExtendDirection.None;
            chart.AxisY.AutoRange = false;
            chart.AxisY.AddRange(0, 35000, 5000);

----
every time click,chart.SelectItems will add 1 .
ChartSelectionMode.Single is not use,why?


3 Answers, 1 is accepted

Sort by
0
Giuseppe
Telerik team
answered on 29 Dec 2010, 07:04 PM
Hello ji,

We tested the described scenario and it behaves as expected -- there is always at most one selected item in the bar series (that is what SelectionMode.Single means).

Find attached a sample application for your reference.


Kind regards,
Freddie
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
ji
Top achievements
Rank 1
answered on 31 Dec 2010, 07:59 AM

Thank you.

After I change my code by sample application,SelectedItems.Count is always 1.

but these code will not behaves as expected ,i think these is a bug.

<Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
      
            <RowDefinition Height="*"/>
   
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <telerik:RadChart Name="RadChart1" Grid.Row="0" />

        <telerik:ChartArea Name="chart2" Grid.Row="1"   />
    </Grid>



//**********************

namespace SilverlightApplication1
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            List<ChartData> data = new List<ChartData>();
            data.Add(new ChartData() { Y = 10 });
            data.Add(new ChartData() { Y = 20 });
            data.Add(new ChartData() { Y = 30 });
            data.Add(new ChartData() { Y = 40 });

            SeriesMapping sm = new SeriesMapping();
            sm.SeriesDefinition = new BarSeriesDefinition();
            sm.SeriesDefinition.InteractivitySettings.HoverScope = InteractivityScope.Item;
            sm.SeriesDefinition.InteractivitySettings.SelectionScope = InteractivityScope.Item;
            sm.SeriesDefinition.InteractivitySettings.SelectionMode = ChartSelectionMode.Single;
            sm.ItemMappings.Add(new ItemMapping("Y", DataPointMember.YValue));

            RadChart1.DefaultView.ChartArea.AxisY.ExtendDirection = AxisExtendDirection.None;
            RadChart1.DefaultView.ChartArea.AxisY.AutoRange = false;
            RadChart1.DefaultView.ChartArea.AxisY.AddRange(0, 100, 10);
            RadChart1.DefaultView.ChartArea.SelectionChanged += new EventHandler<ChartSelectionChangedEventArgs>(ChartArea_SelectionChanged);

            RadChart1.SeriesMappings.Add(sm);
            RadChart1.ItemsSource = data;

            ConfigureZong();
        }

        void ChartArea_SelectionChanged(object sender, ChartSelectionChangedEventArgs e)
        {
            // (sender as ChartArea).SelectedItems.Count is always 1
        }

        private Random rand = new Random(DateTime.Now.Millisecond);

        private void ConfigureZong()
        {
            DataSeries barSeries = GetZong();
            barSeries.Definition.InteractivitySettings.HoverScope = InteractivityScope.Item;
            barSeries.Definition.InteractivitySettings.SelectionScope = InteractivityScope.Item;
            barSeries.Definition.InteractivitySettings.SelectionMode = ChartSelectionMode.Single;

            barSeries.Definition.ShowItemToolTips = true;

            chart2.DataSeries.Add(barSeries);

            chart2.AxisY.Title = "";
            chart2.AxisY.AxisStyles.TitleStyle = Resources["CustomAxisTitleStyle"] as Style;
            chart2.AxisY.ExtendDirection = AxisExtendDirection.None;
            chart2.AxisY.AutoRange = false;
            chart2.AxisY.AddRange(0, 35000, 5000);

        }

        public DataSeries GetZong()
        {
            DataSeries series = new DataSeries();

            for (int i = 4; i > 0; i--)
            {
                DataPoint dataPoint = new DataPoint();
                dataPoint.YValue = rand.Next(20000, 35000);

                DateTime dt = DateTime.Now.AddDays(-i);
                dataPoint.XCategory = dt.ToShortDateString();
                series.Add(dataPoint);
            }

            return series;
        }

    }

    public class ChartData
    {
        public double Y
        {
            get;
            set;
        }
    }
}

0
Giuseppe
Telerik team
answered on 03 Jan 2011, 10:45 AM
Hi ji,

Using external ChartArea like this is not supported by the chart control and may exhibit erroneous behavior. We would suggest you to use second RadChart instance instead of the ChartArea with x:Name="chart2". If you need to customize the default layout, you can set the RadChart.UseDefaultLayout property to false and add your desired layout as content of the RadChart control.

Hope this helps.


All the best,
Freddie
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
Chart
Asked by
ji
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
ji
Top achievements
Rank 1
Share this question
or