WPF 图表 - 类别轴的设置间隔
WPF Charting - Set interval for Category Axis
我已经花了几天时间寻找问题的解决方案,但我还没能解决它。
我向我的 WPF C# 应用程序添加了一个图表,显示每个 DateTime 变量的温度值。我使用了 DotNetProjects.WpfToolkit.DataVisualization 包。我想将 X 轴的标签旋转 90°,并添加了以下代码行:
<s:LineSeries.IndependentAxis>
<s:CategoryAxis
Name="timeax"
ShowGridLines="False"
Title="Time"
Orientation="X">
<s:CategoryAxis.AxisLabelStyle>
<Style
TargetType="s:AxisLabel">
<Setter
Property="Template">
<Setter.Value>
<ControlTemplate
TargetType="s:AxisLabel">
<TextBlock
Text="{TemplateBinding FormattedContent}">
<TextBlock.LayoutTransform>
<RotateTransform
Angle="-90"
CenterX="40"
CenterY="30" />
</TextBlock.LayoutTransform>
</TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</s:CategoryAxis.AxisLabelStyle>
</s:CategoryAxis>
</s:LineSeries.IndependentAxis>
问题是我无法为轴中的值设置间隔,当我有太多值时,结果是这样的:
对于 Y 轴,我可以更改间隔,因为我将它添加为 LinearAxis:
<s:Chart.Axes>
<s:LinearAxis
Orientation="Y"
ShowGridLines="True"
Interval="0.15"
HorizontalAlignment="Left"
/>
</s:Chart.Axes>
但是我不能对 X 轴做同样的事情,因为我想旋转标签。关于如何解决我的问题的任何想法?非常非常非常感谢!
我通过将轴类型从 CategoryAxis 更改为 DateTimeAxis 来解决。这种情况下不需要设置间隔,它会根据window的大小自动结算。
<s:DateTimeAxis
Orientation="X"
Title="Time"
>
<s:DateTimeAxis.AxisLabelStyle>
<Style
TargetType="s:AxisLabel">
<Setter
Property="Template">
<Setter.Value>
<ControlTemplate
TargetType="s:AxisLabel">
<TextBlock
Text="{TemplateBinding FormattedContent}">
<TextBlock.LayoutTransform>
<RotateTransform
Angle="-90" />
</TextBlock.LayoutTransform>
</TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter
Property="StringFormat"
Value="{}{0:dd/MM/yyyy}" />
</Style>
</s:DateTimeAxis.AxisLabelStyle>
</s:DateTimeAxis>
我已经花了几天时间寻找问题的解决方案,但我还没能解决它。
我向我的 WPF C# 应用程序添加了一个图表,显示每个 DateTime 变量的温度值。我使用了 DotNetProjects.WpfToolkit.DataVisualization 包。我想将 X 轴的标签旋转 90°,并添加了以下代码行:
<s:LineSeries.IndependentAxis>
<s:CategoryAxis
Name="timeax"
ShowGridLines="False"
Title="Time"
Orientation="X">
<s:CategoryAxis.AxisLabelStyle>
<Style
TargetType="s:AxisLabel">
<Setter
Property="Template">
<Setter.Value>
<ControlTemplate
TargetType="s:AxisLabel">
<TextBlock
Text="{TemplateBinding FormattedContent}">
<TextBlock.LayoutTransform>
<RotateTransform
Angle="-90"
CenterX="40"
CenterY="30" />
</TextBlock.LayoutTransform>
</TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</s:CategoryAxis.AxisLabelStyle>
</s:CategoryAxis>
</s:LineSeries.IndependentAxis>
问题是我无法为轴中的值设置间隔,当我有太多值时,结果是这样的:
对于 Y 轴,我可以更改间隔,因为我将它添加为 LinearAxis:
<s:Chart.Axes>
<s:LinearAxis
Orientation="Y"
ShowGridLines="True"
Interval="0.15"
HorizontalAlignment="Left"
/>
</s:Chart.Axes>
但是我不能对 X 轴做同样的事情,因为我想旋转标签。关于如何解决我的问题的任何想法?非常非常非常感谢!
我通过将轴类型从 CategoryAxis 更改为 DateTimeAxis 来解决。这种情况下不需要设置间隔,它会根据window的大小自动结算。
<s:DateTimeAxis
Orientation="X"
Title="Time"
>
<s:DateTimeAxis.AxisLabelStyle>
<Style
TargetType="s:AxisLabel">
<Setter
Property="Template">
<Setter.Value>
<ControlTemplate
TargetType="s:AxisLabel">
<TextBlock
Text="{TemplateBinding FormattedContent}">
<TextBlock.LayoutTransform>
<RotateTransform
Angle="-90" />
</TextBlock.LayoutTransform>
</TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter
Property="StringFormat"
Value="{}{0:dd/MM/yyyy}" />
</Style>
</s:DateTimeAxis.AxisLabelStyle>
</s:DateTimeAxis>