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

LineStyle is not working for the chart

3 Answers 101 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Vinod Sardar
Top achievements
Rank 1
Vinod Sardar asked on 19 Jan 2010, 01:21 PM
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.


3 Answers, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 21 Jan 2010, 11:13 AM
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.
0
Vinod Sardar
Top achievements
Rank 1
answered on 21 Jan 2010, 12:12 PM
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.

 

0
Accepted
Ves
Telerik team
answered on 22 Jan 2010, 11:44 AM
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.
Tags
Chart
Asked by
Vinod Sardar
Top achievements
Rank 1
Answers by
Ves
Telerik team
Vinod Sardar
Top achievements
Rank 1
Share this question
or