LineStyle is not working for the chart

4 posts, 1 answers
  1. Vinod Sardar
    Vinod Sardar avatar
    33 posts
    Member since:
    Nov 2009

    Posted 19 Jan 2010 Link to this post

    Hi,

    I am trying to use my own stylepallet for LineSeries.i have defined style pallete in XAML as below:
    <UserControl> 
    <UserControl.Resources> 
            <chart:StylesPalette x:Key="LineStyle">  
                <Style TargetType="Shape">  
                    <Setter Property="Fill" 
                   Value="Yellow" /> 
                </Style> 
                <Style TargetType="Shape">  
                    <Setter Property="Fill" 
                   Value="Orange" /> 
                </Style> 
            </chart:StylesPalette> 
     
     </UserControl.Resources> 
        <Grid x:Name="LayoutRoot" Background="White">  
            <telerik:RadChart x:Name="RadChart1" /> 
        </Grid> 
    </UserControl> 

    following is my code behind file:
        public partial class MainPage : UserControl  
        {
            #region Properties  
     
            public string GroupedBy { getset; }  
            public string XAxisProperty { getset; }  
            public string YAxisProperty { getset; }
            #endregion  
     
            public MainPage()  
            {  
                InitializeComponent();  
                SetProperties();  
                this.Loaded += Page_Loaded;  
            }  
            
            private void Page_Loaded(object sender, RoutedEventArgs e)  
            {  
     
     
                //DataSeries series = new DataSeries();  
                ////series.Definition = new LineSeriesDefinition();  
                //series.Definition = new DoughnutSeriesDefinition();  
                //series.Add(new DataPoint(45) { LegendLabel = "NO" });  
                //series.Add(new DataPoint(55) { LegendLabel = "YES" });  
     
                //RadChart1.DefaultView.ChartArea.DataSeries.Add(series);  
                  
                //RadChart1.Loaded += RadChart1_Loaded;  
                //RadChart1.ItemsSource = series;  
     
     
                ////For STOCKS DATA  
                //SeriesMapping s = new SeriesMapping();  
                //LineSeriesDefinition lineSeries = new LineSeriesDefinition();  
                //s.SeriesDefinition = lineSeries;  
                ////s.LegendLabel = key;  
                ////s.CollectionIndex = groupDic[key];  
                //s.ItemMappings.Add(new ItemMapping(YAxisProperty, DataPointMember.YValue));  
                //s.ItemMappings.Add(new ItemMapping(XAxisProperty, DataPointMember.XCategory));  
                ////s.ChartArea = nomuraChartArea;  
                //RadChart1.SeriesMappings.Add(s);  
     
                //this.RadChart1.DefaultView.ChartArea.SeriesStyles.LineSeriesStyle = this.Resources[ "LineStyle1" ] as Style;              
                RadChart1.DefaultSeriesDefinition = new LineSeriesDefinition();  
                RadChart1.ItemsSource = Stock.GetStocks();  
            }  
     
            private void RadChart1_Loaded(object sender, RoutedEventArgs e)  
            {  
                //RadChart1.DefaultView.ChartLegend.Items[0].Background = new SolidColorBrush(Colors.Red);  
                //RadChart1.DefaultView.ChartLegend.Items[1].Background = new SolidColorBrush(Colors.Green);  
            }  
     
            private void SetProperties()  
            {  
                GroupedBy = "Name";  
                XAxisProperty = "Month";  
                YAxisProperty = "Volume";  
            }  
        }  
     
        public class Stock  
        {  
            public string Name { getset; }  
            public string Month { getset; }  
            public double Volume { getset; }  
            public double Price { getset; }  
     
            public static IEnumerable GetStocks()  
            {  
                List<Stock> _lstStocks = new List<Stock>();  
     
                Stock s9 = new Stock();  
                s9.Name = "Total";  
                s9.Month = "JAN";  
                s9.Volume = 110;  
                s9.Price = 90;  
     
                Stock s10 = new Stock();  
                s10.Name = "Total";  
                s10.Month = "FEB";  
                s10.Volume = 160;  
                s10.Price = 125;  
     
                Stock s11 = new Stock();  
                s11.Name = "Total";  
                s11.Month = "March";  
                s11.Volume = 140;  
                s11.Price = 150;  
     
                Stock s12 = new Stock();  
                s12.Name = "Total";  
                s12.Month = "April";  
                s12.Volume = 110;  
                s12.Price = 97;  
     
                Stock s13 = new Stock();  
                s13.Name = "Total";  
                s13.Month = "May";  
                s13.Volume = 290;  
                s13.Price = 210;  
     
                Stock s14 = new Stock();  
                s14.Name = "Total";  
                s14.Month = "June";  
                s14.Volume = 140;  
                s14.Price = 185;  
     
     
                //Institutional  
                Stock s15 = new Stock();  
                s15.Name = "Institutional";  
                s15.Month = "JAN";  
                s15.Volume = 110;  
                s15.Price = 90;  
     
                Stock s16 = new Stock();  
                s16.Name = "Institutional";  
                s16.Month = "FEB";  
                s16.Volume = 160;  
                s16.Price = 125;  
     
                Stock s17 = new Stock();  
                s17.Name = "Institutional";  
                s17.Month = "March";  
                s17.Volume = 90;  
                s17.Price = 150;  
     
                Stock s18 = new Stock();  
                s18.Name = "Institutional";  
                s18.Month = "April";  
                s18.Volume = 145;  
                s18.Price = 97;  
     
                Stock s19 = new Stock();  
                s19.Name = "Institutional";  
                s19.Month = "May";  
                s19.Volume = 189;  
                s19.Price = 210;  
     
                Stock s20 = new Stock();  
                s20.Name = "Institutional";  
                s20.Month = "June";  
                s20.Volume = 120;  
                s20.Price = 185;  
     
     
                //For Total  
                _lstStocks.Add(s9);  
                _lstStocks.Add(s10);  
                _lstStocks.Add(s11);  
                _lstStocks.Add(s12);  
                _lstStocks.Add(s13);  
                _lstStocks.Add(s14);  
     
                //for institutional  
                _lstStocks.Add(s15);  
                _lstStocks.Add(s16);  
                _lstStocks.Add(s17);  
                _lstStocks.Add(s18);  
                _lstStocks.Add(s19);  
                _lstStocks.Add(s20);  
     
     
                return _lstStocks as IEnumerable;  
            }  
     
            public static List<Stock> GetStocksWithIndexList()  
            {  
     
                List<List<Stock>> _indexList = new List<List<Stock>>();  
                List<Stock> _lstStocks = new List<Stock>();  
     
                Stock s9 = new Stock();  
                s9.Name = "Total";  
                s9.Month = "JAN";  
                s9.Volume = 110;  
                s9.Price = 90;  
     
                Stock s10 = new Stock();  
                s10.Name = "Total";  
                s10.Month = "FEB";  
                s10.Volume = 160;  
                s10.Price = 125;  
     
                Stock s11 = new Stock();  
                s11.Name = "Total";  
                s11.Month = "March";  
                s11.Volume = 140;  
                s11.Price = 150;  
     
                Stock s12 = new Stock();  
                s12.Name = "Total";  
                s12.Month = "April";  
                s12.Volume = 110;  
                s12.Price = 97;  
     
                Stock s13 = new Stock();  
                s13.Name = "Total";  
                s13.Month = "May";  
                s13.Volume = 290;  
                s13.Price = 210;  
     
                Stock s14 = new Stock();  
                s14.Name = "Total";  
                s14.Month = "June";  
                s14.Volume = 140;  
                s14.Price = 185;  
     
     
                //Institutional  
                Stock s15 = new Stock();  
                s15.Name = "Institutional";  
                s15.Month = "JAN";  
                s15.Volume = 110;  
                s15.Price = 90;  
     
                Stock s16 = new Stock();  
                s16.Name = "Institutional";  
                s16.Month = "FEB";  
                s16.Volume = 160;  
                s16.Price = 125;  
     
                Stock s17 = new Stock();  
                s17.Name = "Institutional";  
                s17.Month = "March";  
                s17.Volume = 90;  
                s17.Price = 150;  
     
                Stock s18 = new Stock();  
                s18.Name = "Institutional";  
                s18.Month = "April";  
                s18.Volume = 145;  
                s18.Price = 97;  
     
                Stock s19 = new Stock();  
                s19.Name = "Institutional";  
                s19.Month = "May";  
                s19.Volume = 189;  
                s19.Price = 210;  
     
                Stock s20 = new Stock();  
                s20.Name = "Institutional";  
                s20.Month = "June";  
                s20.Volume = 120;  
                s20.Price = 185;  
     
     
                //For Total  
                _lstStocks.Add(s9);  
                _lstStocks.Add(s11);  
                _lstStocks.Add(s12);  
                _lstStocks.Add(s13);  
                _lstStocks.Add(s14);  
     
                //for institutional  
                _lstStocks.Add(s15);  
                _lstStocks.Add(s16);  
                _lstStocks.Add(s17);  
                _lstStocks.Add(s18);  
                _lstStocks.Add(s19);  
                _lstStocks.Add(s20);  
     
                _indexList.Add(_lstStocks);  
                //_indexList.Add(_lstStocks);  
     
                return _lstStocks;  
            }  
        } 


    Error:
    "Unhandled error in Silverlight application.Code:4004,Category:ManagedRuntime Error".

    Please let me know what is wrong with the code.? and how to resolve this issue.
    I am using DLL-"Telerik.Windows.Controls.Charting" Version:"2009.3.1314.1030"


    One more thing: Wt I have observed is that- If I use DataSeries , Line Style gets applied to the chart. (NOTE:I don;t want to use line series. :) I want to use Series Mapping for Chart. )

    Thanks,
    Vinod Sardar.


  2. Ves
    Admin
    Ves avatar
    2926 posts

    Posted 21 Jan 2010 Link to this post

    Hello Vinod,

    Here is an example of a custom palette:

        <Style TargetType="chart:SelfDrawingSeries">
            <Setter Property="BorderLineStyle">
                <Setter.Value>
                    <Style TargetType="Shape" >
                        <Setter Property="StrokeThickness" Value="2" />
                        <Setter Property="Fill" Value="Yellow" />
                        <Setter Property="Stroke" Value="Yellow" />
                    </Style>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="chart:SelfDrawingSeries">
            <Setter Property="BorderLineStyle">
                <Setter.Value>
                    <Style TargetType="Shape" >
                        <Setter Property="StrokeThickness" Value="2" />
                        <Setter Property="Fill" Value="Green" />
                        <Setter Property="Stroke" Value="Green" />
                    </Style>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="chart:SelfDrawingSeries">
            <Setter Property="BorderLineStyle">
                <Setter.Value>
                    <Style TargetType="Shape" >
                        <Setter Property="StrokeThickness" Value="2" />
                        <Setter Property="Fill" Value="Red" />
                        <Setter Property="Stroke" Value="Red" />
                    </Style>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="chart:SelfDrawingSeries">
            <Setter Property="BorderLineStyle">
                <Setter.Value>
                    <Style TargetType="Shape" >
                        <Setter Property="StrokeThickness" Value="2" />
                        <Setter Property="Fill" Value="Blue" />
                        <Setter Property="Stroke" Value="Blue" />
                    </Style>
                </Setter.Value>
            </Setter>
        </Style>
    </chart:StylesPalette>

    This will work with series mapping, without the need of setting the style for each line series individually.

    Best regards,
    Ves
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Vinod Sardar
    Vinod Sardar avatar
    33 posts
    Member since:
    Nov 2009

    Posted 21 Jan 2010 Link to this post

    Thanks for the reply.

    I guess some things are missing.

    Please let me know followg:
    1.Will it be automatically applied like series mapping?
     (I have tried but not get automatically applied)

    2. How and for what we should apply this style.
    *I have applied as follows:

    SeriesMapping

     

    s = new SeriesMapping();

     

     

     

    LineSeriesDefinition lineSeries = new LineSeriesDefinition();

     

    s.SeriesDefinition = lineSeries;

    s.SeriesDefinition.SeriesStyle =

    this.Resources["cutomStylePallate"] as Style;

    But it is not working.

    Coudl you please provide me SAMPLE PROJECT.

    Thanks,
    Vinod Sardar.

     

  4. Answer
    Ves
    Admin
    Ves avatar
    2926 posts

    Posted 22 Jan 2010 Link to this post

    Hello Vinod,

    You will not need to assign style. Just make sure the styles palette is defined as uppermost user control resource or application resource. I have attached a small example, just add the Telerik.Windows.Controls, Telerik.Windows.Controls.Charting and Telerik.Windows.Data assemblies.

    Sincerely,
    Ves
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top