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

Custom Palette for line series not working.

2 Answers 124 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Rahul
Top achievements
Rank 2
Rahul asked on 16 Mar 2011, 02:46 PM
I'm using custom palette for Line series but its not working.
I'm posting my code here. Plz have a look and answer.

private void MultipleYAxis()
      {
 
          //Custom Point Mark Style
          radChart1.DefaultSeriesDefinition.PointMarkItemStyle = this.radChart1.Resources["CustomStyle"] as Style;
 
          radChart1.DefaultView.ChartArea.AdditionalYAxes.Add(new AxisY());
          radChart1.DefaultView.ChartArea.AdditionalYAxes.Add(new AxisY());
          radChart1.DefaultView.ChartArea.AdditionalYAxes.Add(new AxisY());
          radChart1.DefaultView.ChartArea.AdditionalYAxes[0].AxisName = "Visits";
          radChart1.DefaultView.ChartArea.AdditionalYAxes[1].AxisName = "IMPVisits";
          radChart1.DefaultView.ChartArea.AdditionalYAxes[2].AxisName = "MissedVisits";
 
          //radChart1.DefaultSeriesDefinition.InteractivitySettings.HoverScope = InteractivityScope.Series;
          //radChart1.DefaultSeriesDefinition.InteractivitySettings.SelectionScope = InteractivityScope.Series;
           
          //Hide Y Axis
          radChart1.DefaultView.ChartArea.AxisY.Visibility = Visibility.Collapsed;
 
          //Styles for axises
          radChart1.DefaultView.ChartArea.AdditionalYAxes[0].AxisStyles.AxisLineStyle = this.Resources["CustomAxisYStyle3"] as Style;
          //radChart1.DefaultView.ChartArea.AdditionalYAxes[0].AxisStyles.TickLineStyle = this.Resources["CustomAxisYStyle3"] as Style;
          //radChart1.DefaultView.ChartArea.AdditionalYAxes[0].AxisStyles.MinorTickLineStyle = this.Resources["CustomAxisYStyle3"] as Style;
 
          radChart1.DefaultView.ChartArea.AdditionalYAxes[1].AxisStyles.AxisLineStyle = this.Resources["CustomAxisYStyle2"] as Style;
          radChart1.DefaultView.ChartArea.AdditionalYAxes[1].AxisStyles.TickLineStyle = this.Resources["CustomAxisYStyle2"] as Style;
          radChart1.DefaultView.ChartArea.AdditionalYAxes[1].AxisStyles.MinorTickLineStyle = this.Resources["CustomAxisYStyle2"] as Style;
 
          radChart1.DefaultView.ChartArea.AdditionalYAxes[2].AxisStyles.AxisLineStyle = this.Resources["CustomAxisYStyle1"] as Style;
          radChart1.DefaultView.ChartArea.AdditionalYAxes[2].AxisStyles.TickLineStyle = this.Resources["CustomAxisYStyle1"] as Style;
          radChart1.DefaultView.ChartArea.AdditionalYAxes[2].AxisStyles.MinorTickLineStyle = this.Resources["CustomAxisYStyle1"] as Style;
 
          //Series mapping for the collection with index 0
          SeriesMapping seriesMapping = new SeriesMapping();
          seriesMapping.SeriesDefinition = new LineSeriesDefinition() { PointMarkItemStyle = this.Resources["CustomStyle"] as Style};
          seriesMapping.SeriesDefinition.InteractivitySettings.HoverScope = InteractivityScope.Series;
          seriesMapping.SeriesDefinition.AxisName = "Visits";
          seriesMapping.LegendLabel = "Visits";
          seriesMapping.SeriesDefinition.ShowItemLabels = false;
          seriesMapping.ItemMappings.Add( new ItemMapping( "Visits", DataPointMember.YValue ) );
          seriesMapping.ItemMappings.Add(new ItemMapping("Date", DataPointMember.XValue));
          radChart1.SeriesMappings.Add( seriesMapping );
 
          seriesMapping = new SeriesMapping();
          seriesMapping.LegendLabel = "IMPVisits";
          seriesMapping.SeriesDefinition = new LineSeriesDefinition();
          seriesMapping.SeriesDefinition.InteractivitySettings.HoverScope = InteractivityScope.Series;
          seriesMapping.SeriesDefinition.AxisName = "IMPVisits";
          seriesMapping.SeriesDefinition.ShowItemLabels = false;
          seriesMapping.ItemMappings.Add( new ItemMapping( "IMPVisits", DataPointMember.YValue ) );
          seriesMapping.ItemMappings.Add(new ItemMapping("Date", DataPointMember.XValue));
          radChart1.SeriesMappings.Add( seriesMapping );
 
          seriesMapping = new SeriesMapping();
          seriesMapping.LegendLabel = "Missed Visits";
          seriesMapping.SeriesDefinition = new LineSeriesDefinition();
          seriesMapping.SeriesDefinition.InteractivitySettings.HoverScope = InteractivityScope.Series;
          seriesMapping.SeriesDefinition.AxisName = "MissedVisits";
          seriesMapping.SeriesDefinition.ShowItemLabels = false;
          seriesMapping.ItemMappings.Add(new ItemMapping("MissedVisits", DataPointMember.YValue));
          seriesMapping.ItemMappings.Add(new ItemMapping("Date", DataPointMember.XValue));
          radChart1.SeriesMappings.Add(seriesMapping);
 
 
          //Chart Legend
          radChart1.DefaultView.ChartLegend.UseAutoGeneratedItems = true;
          radChart1.DefaultView.ChartLegend.Header = "Monthly Visits";
          radChart1.DefaultView.ChartLegendPosition = Telerik.Windows.Controls.Dock.Top;
 
          //Chart X-Axis Labels
          radChart1.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "dd-MMM-yyyy";
          radChart1.DefaultView.ChartArea.AxisX.LabelRotationAngle = 50;
 
          //Chart Custom Tool Tips           
          radChart1.DefaultView.ChartArea.ItemToolTipOpening += this.ChartItemToolTipOpening;
 
 
 
          //Chart Axis Style
          //this.radChart1.DefaultView.ChartArea.AxisX.AxisStyles.TickLineStyle = this.Resources["CustomAxisYStyle1"] as Style;
          //this.radChart1.DefaultView.ChartArea.AxisY.AxisStyles.AxisLineStyle = this.Resources["CustomAxisYStyle2"] as Style;
 
          //Custom color Palette for Line Series
          Color[] colors = new Color[] { Colors.Purple, Colors.Yellow, Colors.Blue, Colors.Green };
          for (int i = 0; i < radChart1.SeriesMappings.Count; i++)
          {
              radChart1.SeriesMappings[i].SeriesDefinition.Appearance.Fill = colors[i];
          }
 
           
 
          radChart1.ItemsSource = new TrafficInfoCollection();
         
      }

Check out the Bold & Italic Code which i designed for Custom Palette for Line Series.

2 Answers, 1 is accepted

Sort by
0
Accepted
Sia
Telerik team
answered on 18 Mar 2011, 12:58 PM
Hello Rahul,

You need to modify your code in order to make it work as follows:
Color[] colors = new Color[] { Colors.Purple, Colors.Yellow, Colors.Blue, Colors.Green };
 for (int i = 0; i < RadChart1.SeriesMappings.Count; i++)
{
       RadChart1.SeriesMappings[i].SeriesDefinition.Appearance.Stroke = new SolidColorBrush(colors[i]);
}

However, I suggest you to try our Palette Brushes functionality.

Best wishes,
Sia
the Telerik team
0
Rahul
Top achievements
Rank 2
answered on 18 Mar 2011, 03:01 PM
Thanks a lot Sia. That's what I want.
Thanks once again.
Tags
Chart
Asked by
Rahul
Top achievements
Rank 2
Answers by
Sia
Telerik team
Rahul
Top achievements
Rank 2
Share this question
or