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

X-Axis Date Range

1 Answer 59 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Angie
Top achievements
Rank 1
Angie asked on 10 May 2012, 09:38 PM
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>


1 Answer, 1 is accepted

Sort by
0
Angie
Top achievements
Rank 1
answered on 10 May 2012, 09:46 PM
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");
            }



Tags
Chart
Asked by
Angie
Top achievements
Rank 1
Answers by
Angie
Top achievements
Rank 1
Share this question
or