i have been running into a crash when i attempt to put the chart area into a scrollviewer. I am trying to get it so that i can display all the information on the x Axis without it ending up all smashed togther. Here is the code i am using Also is there any option that allow you to control the spacing of the X axis so that the information is not smashed together if a lot of info is present? Or a scroll bar option already available?
XAML
codebehind
XAML
<UserControl x:Class="ChartTheme.Page" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:control="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting" |
xmlns:chart="clr-namespace:Telerik.Windows.Controls.Charting;assembly=Telerik.Windows.Controls.Charting" |
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" |
Width="1024" |
Height="768"> |
<Grid x:Name="LayoutRoot" |
Background="White"> |
<control:RadChart x:Name="RadChart1" |
VerticalAlignment="Stretch" |
HorizontalAlignment="Stretch" |
UseDefaultLayout="False" |
Background="Transparent"> |
<Grid> |
<Grid.RowDefinitions> |
<RowDefinition Height="10" /> |
<RowDefinition Height="*" /> |
</Grid.RowDefinitions> |
<Grid.ColumnDefinitions> |
<ColumnDefinition Width="*" /> |
<ColumnDefinition Width="Auto" |
MinWidth="104" /> |
</Grid.ColumnDefinitions> |
<chart:ChartLegend x:Name="RadChartLegend" |
Header="Temperatures" |
Visibility="Visible" |
Background="Aqua" |
Grid.Column="1" |
Grid.Row="1" |
Padding="-10, 20, 20, 30" |
Margin="0,0,0,0" |
HorizontalAlignment="Stretch" |
VerticalAlignment="Stretch" /> |
<ScrollViewer Grid.Row="1"> |
<chart:ChartArea x:Name="RadChart2" |
LegendName="RadChartLegend" |
Background="#FFFFFFFF" |
Height="Auto" |
Width="Auto" |
DimensionMode="Strict2D" |
ItemWidthPercent="90" |
HorizontalContentAlignment="Center" |
UseLayoutRounding="True" |
/> |
</ScrollViewer> |
</Grid> |
</control:RadChart> |
</Grid> |
</UserControl> |
codebehind
using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Net; |
using System.Windows; |
using System.Windows.Controls; |
using System.Windows.Documents; |
using System.Windows.Input; |
using System.Windows.Media; |
using System.Windows.Media.Animation; |
using System.Windows.Shapes; |
using Telerik.Windows.Controls.Charting; |
namespace ChartTheme |
{ |
public partial class Page : UserControl |
{ |
public Page() |
{ |
InitializeComponent(); |
Loaded += new RoutedEventHandler(Page_Loaded); |
} |
private void Page_Loaded(object sender, RoutedEventArgs e) |
{ |
DataSeries barSeries = new DataSeries(); |
barSeries.Definition = new BarSeriesDefinition(); |
this.FillWithSampleData(barSeries, 100); |
RadChart2.DataSeries.Clear(); |
RadChart2.AxisY.AutoRange = true; |
RadChart2.DataSeries.Add(barSeries); |
} |
private void FillWithSampleData(DataSeries series, int numberOfItems) |
{ |
Random random = new Random((int)(series.GetHashCode() + DateTime.Now.Ticks)); |
for(int i = 0; i < numberOfItems; i++) |
{ |
int randomNumber = random.Next(30, 100); |
series.Add(new DataPoint |
{ |
XValue = randomNumber, |
YValue = randomNumber |
}); |
} |
} |
} |
} |