X-Axis Date Range

2 posts, 0 answers
  1. Angie
    Angie avatar
    101 posts
    Member since:
    Jan 2008

    Posted 10 May 2012 Link to this post

    Hello, I am evaluating the Silverlight controls and am trying to create a line chart.    I am having problems similar to this thread:  

    http://www.telerik.com/community/forums/silverlight/chart/adding-1-month-intervals-to-chart-x-axis-range.aspx.

    I would like my x-axis data labels to line up with the actual data points, as is shown in the attached image.  However, as soon as I declare the actual date field as the value for the x-axis, the data points become dis-aligned and I end up with a gap on the right side of the chart.

    I believe the solution is to follow the response of the above thread, which was to manually change the value of the tickpoints, however, it does not state how to do this.

    I tried something like this, but it is not working at all:

    for (int i=0;i<radChart.DefaultView.ChartArea.AxisX.TickPoints.Count;i++)
               {
                   radChart.DefaultView.ChartArea.AxisX.TickPoints[i].Label = ((DateTime)e.Result[i].stat_date).ToString("MMM-YY");
           }

    Any assistance would be welcome.  Thank you.

    Chart code:

    <telerik:RadChart x:Name="RadChart1">
                <telerik:RadChart.DefaultSeriesDefinition>
                    <telerik:LineSeriesDefinition />
                </telerik:RadChart.DefaultSeriesDefinition>
                <telerik:RadChart.DefaultView>
                    <telerik:ChartDefaultView>
                        <telerik:ChartDefaultView.ChartArea>
                            <telerik:ChartArea LabelFormatBehavior="None">
                                <telerik:ChartArea.AxisX>
                                    <telerik:AxisX IsDateTime="False" AutoRange="True"     >
                                    </telerik:AxisX>
                                </telerik:ChartArea.AxisX>
                            </telerik:ChartArea>
                        </telerik:ChartDefaultView.ChartArea>
                    </telerik:ChartDefaultView>
                </telerik:RadChart.DefaultView>
                <telerik:RadChart.SeriesMappings>
                    <telerik:SeriesMapping>
                        <telerik:SeriesMapping.ItemMappings>
                            <telerik:ItemMapping FieldName="new_registrants" DataPointMember="YValue" />
                             
                        </telerik:SeriesMapping.ItemMappings>
                    </telerik:SeriesMapping>
                </telerik:RadChart.SeriesMappings>
            </telerik:RadChart>


  2. Angie
    Angie avatar
    101 posts
    Member since:
    Jan 2008

    Posted 10 May 2012 Link to this post

    Oh dear, and this is what happens when you have way too many test pages and test charts.

    Obviously, in the above example, Radchart should be RadChart1 and the code works just fine.

    So to answer my own question, the code to manually set the labels is indeed:

    for (int i = 0; i < RadChart1.DefaultView.ChartArea.AxisX.TickPoints.Count; i++)
                {
                    RadChart1.DefaultView.ChartArea.AxisX.TickPoints[i].Label = ((DateTime)e.Result[i].stat_date).ToString("MMM-yy");
                }



  3. DevCraft banner
Back to Top