我尝试使用带有两条绘图线的WPF工具包创建折线图。图表将显示最近30天并使X轴标签更易于阅读我想将标签转换为45度角并显示每隔三个标签。我对标签角度有问题并且每隔三分之一显示一次。
代码示例:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:DVC="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
Title="Chart Samples" Height="600" Width="1025">
<Grid Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="300"/>
<RowDefinition Height="300"/>
</Grid.RowDefinitions>
<DVC:Chart Grid.Row="0" Name="HphChart2" Width="400" Height="250" LegendTitle="Roads" Title="Line Series HPH Roads Per Day" Padding="1">
<DVC:Chart.Axes>
<DVC:LinearAxis Orientation="Y" HorizontalAlignment="Left" Title="Horse Power Hours" Background="Linen"/>
<DVC:CategoryAxis Orientation="X" Title="Days" />
</DVC:Chart.Axes>
<DVC:Chart.Series>
<!-- Road 1 -->
<DVC:LineSeries Title="Rd-1"
IndependentValuePath="Key"
DependentValuePath="Value"
ToolTip="Y = #VALY\nX = #VALX">
<DVC:LineSeries.DataPointStyle>
<Style TargetType="DVC:LineDataPoint">
<Setter Property="Background" Value="DarkRed"/>
<Setter Property="Visibility" Value="Collapsed"/>
</Style>
</DVC:LineSeries.DataPointStyle>
</DVC:LineSeries>
<!-- Road 2 -->
<DVC:LineSeries Title="Rd-2"
IndependentValuePath="Key"
DependentValuePath="Value" >
<DVC:LineSeries.DataPointStyle>
<Style TargetType="DVC:LineDataPoint">
<Setter Property="Background" Value="Black"/>
<Setter Property="Visibility" Value="Collapsed"/>
</Style>
</DVC:LineSeries.DataPointStyle>
</DVC:LineSeries>
</DVC:Chart.Series>
</DVC:Chart>
</Grid>
</Window>
public MainWindow()
{
InitializeComponent();
LoadAreaChartData();
}
private void LoadAreaChartData()
{
//Road 1
((LineSeries)HphChart2.Series[0]).ItemsSource =
new KeyValuePair<string, int>[]{
new KeyValuePair<string, int>("01/29/14", 100),
new KeyValuePair<string, int>("01/30/14", 180),
new KeyValuePair<string, int>("01/31/14", 110),
new KeyValuePair<string, int>("02/01/14", 95),
new KeyValuePair<string, int>("02/02/14", 40),
new KeyValuePair<string, int>("02/03/14", 95)
};
//Road 2
((LineSeries)HphChart2.Series[1]).ItemsSource =
new KeyValuePair<string, int>[]{
new KeyValuePair<string, int>("01/29/14", 150),
new KeyValuePair<string, int>("01/30/14", 100),
new KeyValuePair<string, int>("01/31/14", 80),
new KeyValuePair<string, int>("02/01/14", 95),
new KeyValuePair<string, int>("02/02/14", 90),
new KeyValuePair<string, int>("02/03/14", 190)
};
}