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

Skipping Major Grid Lines?

5 Answers 123 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Jeff Kershner
Top achievements
Rank 1
Jeff Kershner asked on 16 Nov 2010, 05:29 PM

chart.DefaultView.ChartArea.AxisX.MajorGridLinesVisibility =

 

Visibility.Visible;

 


The above line draws the major grid lines.  Is there a way to show only every 4th major grid line?

Thanks,
--Jeff

5 Answers, 1 is accepted

Sort by
0
Rafał
Top achievements
Rank 1
answered on 17 Nov 2010, 11:37 AM
I have the same question.
Appreciate for quick response.

best regards
Rafac
0
Evgenia
Telerik team
answered on 18 Nov 2010, 05:03 PM
Hi Jeff and Rafał,

As there is no way to loop through the MajorGridLines you can use the following approach to show only every 4th major grid line:
Turn off AxisX's MajorGridLines Visibility. Use Marked Zones (http://www.telerik.com/help/aspnet-ajax/featuresmarkedzones.html) and set their values for ValueStartX , ValueEndX and ValueStartY, ValueEndY  properties (as shown in the code snippet below). Use the border to specify the line color and style. I hope that this sample will be descriptive enough:

protected void Page_Load(object sender, EventArgs e)
   {
       RadChart2.PlotArea.YAxis.AxisMode = Telerik.Charting.ChartYAxisMode.Extended;
       RadChart2.PlotArea.XAxis.LayoutMode = Telerik.Charting.Styles.ChartAxisLayoutMode.Normal;
       RadChart2.PlotArea.XAxis.AutoScale = false;
       RadChart2.PlotArea.XAxis.AddRange(0,16,1);
       for (int i = 0; i < RadChart2.PlotArea.XAxis.MaxValue; i+=3)
       {
           Telerik.Charting.ChartMarkedZone myCustomGridLine = new Telerik.Charting.ChartMarkedZone();
           myCustomGridLine.ValueStartY = RadChart2.PlotArea.YAxis.MinValue;
           myCustomGridLine.ValueEndY = RadChart2.PlotArea.YAxis.MaxValue;
           myCustomGridLine.ValueStartX = i + 3;
           myCustomGridLine.ValueEndX = i + 3;
           myCustomGridLine.Appearance.Border.Color = System.Drawing.Color.Red;
           myCustomGridLine.Appearance.Border.Width = 0.5f;
           myCustomGridLine.Appearance.Visible = true;
           RadChart2.PlotArea.MarkedZones.Add(myCustomGridLine);
       }
   }
Note that I set custom Range to XAxis so that I am able to loop through it's items and create Marked Zone on the place of every 4-th MajorGridLine. Also as ValueStartX and ValueEndX of the zone are equal the zone looks like a line.
Have in mind that you can use Line Series instead of Marked Zones and the approach will be same as shown above.

All the best,
Evgenia
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Rafał
Top achievements
Rank 1
answered on 19 Nov 2010, 10:33 AM
thanks..
this solves the problem..

best regards
Rafac
0
Jeff Kershner
Top achievements
Rank 1
answered on 19 Nov 2010, 04:27 PM
Is there a RadChart for Silverlight solution to this problem?
0
Accepted
Evgenia
Telerik team
answered on 23 Nov 2010, 01:03 PM
Hello Jeff,

There are 3 ways to achieve this in RadChart for Silverlight. As there is no way to loop through the MajorGridLines set their visibility to collapsed. Then you can use MarkedZone (http://www.telerik.com/help/silverlight/radchart-features-annotations-marked-zone.html), CustomGridLine(http://www.telerik.com/help/silverlight/radchart-features-annotations-custom-gridline.html) or CustomLine (http://www.telerik.com/help/silverlight/radchart-features-annotations-custom-line.html) to imitate the MajorGridLines.
Here is how you can achive this with Custom GridLines:
RadChart1.DefaultView.ChartArea.AxisX.MajorGridLinesVisibility = System.Windows.Visibility.Collapsed;
           RadChart1.DefaultView.ChartArea.AxisX.LayoutMode = AxisLayoutMode.Normal;
           RadChart1.DefaultView.ChartArea.AxisX.AutoRange = false;
           RadChart1.DefaultView.ChartArea.AxisX.AddRange(0, 16, 1);
           for (int i = 0; i < RadChart1.DefaultView.ChartArea.AxisX.MaxValue; i += 3)
           {
               CustomGridLine gridline = new CustomGridLine();
               gridline.XIntercept = i + 3;
               gridline.Stroke = new SolidColorBrush(Colors.Red);
               gridline.StrokeThickness = 2;
               this.RadChart1.DefaultView.ChartArea.Annotations.Add(gridline); 
           }

And the same approach but with MarkedZone:
RadChart1.DefaultView.ChartArea.AxisX.MajorGridLinesVisibility = System.Windows.Visibility.Collapsed;
           RadChart1.DefaultView.ChartArea.AxisX.LayoutMode = AxisLayoutMode.Normal;
           RadChart1.DefaultView.ChartArea.AxisX.AutoRange = false;
           RadChart1.DefaultView.ChartArea.AxisX.AddRange(0, 16, 1);
           for (int i = 0; i < RadChart1.DefaultView.ChartArea.AxisX.MaxValue; i += 3)
           {
               MarkedZone myCustomZone = new MarkedZone();
               myCustomZone.StartX = i + 3;
               myCustomZone.EndX = i + 3 + 0.01;
               myCustomZone.BorderBrush = new SolidColorBrush(Colors.Blue);
               myCustomZone.Background = new SolidColorBrush(Colors.Blue);
               this.RadChart1.DefaultView.ChartArea.Annotations.Add(myCustomZone);
           }
Note that EndX is same as StartX but increased with 0.01. Change this value to control the Width of the MarkedZone.

Creating Custom Line is not way different from the approaches shown above.

Kind regards,
Evgenia
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Chart (Obsolete)
Asked by
Jeff Kershner
Top achievements
Rank 1
Answers by
Rafał
Top achievements
Rank 1
Evgenia
Telerik team
Jeff Kershner
Top achievements
Rank 1
Share this question
or