C# WPF图表:在Y轴上垂直显示文本
在我的图表中,我想在Y轴之前显示文本作为Y轴中心的垂直标题,如“%Volume”,在X轴下方显示文本作为“Sales”。如何分别在X轴和Y轴上添加这些标签?我的XML代码是:C# WPF图表:在Y轴上垂直显示文本,c#,wpf,charts,wpftoolkit,C#,Wpf,Charts,Wpftoolkit,在我的图表中,我想在Y轴之前显示文本作为Y轴中心的垂直标题,如“%Volume”,在X轴下方显示文本作为“Sales”。如何分别在X轴和Y轴上添加这些标签?我的XML代码是: Grid> <DVC:Chart Name="bsiPlaceChart" Title="SI Placement" LegendTitle="Legend" Width="850" Height="450"> <DVC:Chart.Series>
Grid>
<DVC:Chart Name="bsiPlaceChart" Title="SI Placement" LegendTitle="Legend" Width="850" Height="450">
<DVC:Chart.Series>
<DVC:ColumnSeries Name="layer1Chart" Title="Title 1" ItemsSource="{Binding}" IndependentValuePath="Name"
DependentValuePath="Volume"></DVC:ColumnSeries>
<DVC:ColumnSeries Name="layer2Chart" Title="Title 2" ItemsSource="{Binding}" IndependentValuePath="Name"
DependentValuePath="Volume" ></DVC:ColumnSeries>
<DVC:ColumnSeries Name="layer3Chart" Title="Title 3" ItemsSource="{Binding}" IndependentValuePath="Name"
DependentValuePath="Volume" ></DVC:ColumnSeries>
</DVC:Chart.Series>
</DVC:Chart>
<TextBlock HorizontalAlignment="Center" Text="Layers" FontSize="12" FontWeight="Bold" Margin="343,440,472,0" />
</Grid>
Grid>
对于X轴,我尝试在图表下方添加一个文本块,但当窗口大小改变时,文本也会上下移动。我希望它保持在图表下方,就好像它是图表的一部分一样
如何分别为X轴和Y轴设置此类标题
更新:
Paul提供的解决方案:
我分别为X轴和Y轴添加了资源:
<Grid.Resources>
<DVC:LinearAxis Orientation="Y" Title="% Volume" HorizontalAlignment="Left" x:Key="YAxis" />
<DVC:LinearAxis Orientation="X" Title="Layers" HorizontalAlignment="Center" x:Key="XAxis" />
</Grid.Resources>
在每个列系列中,修改如下:
<DVC:ColumnSeries Name="layer1Chart" Title="Viscosity 1" ItemsSource="{Binding}" IndependentValuePath="Name" DependentValuePath="Volume" DependentRangeAxis="{StaticResource YAxis}">
</DVC:ColumnSeries>
这管理了Y轴点。如何将XAxis也添加到其中
解决方案:
删除资源并在图表中添加图表轴,如下所示。这将在Y轴左侧添加“%Volume”标签,在X轴底部添加“Layers”标签。太好了
<!-- Add Title on Y axis and X Axis -->
<DVC:Chart.Axes>
<DVC:LinearAxis Orientation="Y" Title="% Volume" HorizontalAlignment="Left" />
<DVC:CategoryAxis Orientation="X" Title="Layers" Location="Bottom" />
</DVC:Chart.Axes>
谢谢你,保罗。像下面这样的东西应该可以做到:
<charting:LineSeries.DependentRangeAxis>
<charting:LinearAxis Orientation="Y" Title="Y Axis"/>
</charting:LineSeries.DependentRangeAxis>
读一读这个和另一个
编辑:取自,要设置x轴和y轴,请执行以下操作
<charting:Chart.Axes>
<charting:LinearAxis Orientation="Y">
<charting:LinearAxis.Title>
<ContentControl ContentTemplate="{StaticResource YAxisTitleContentTemplate}"/>
</charting:LinearAxis.Title>
</charting:LinearAxis>
<charting:CategoryAxis Orientation="X">
<charting:CategoryAxis.Title>
<ContentControl ContentTemplate="{StaticResource XAxisTitleContentTemplate}"/>
</charting:CategoryAxis.Title>
</charting:CategoryAxis>
</charting:Chart.Axes>
仅适用于X轴:
<charting:Chart.Axes>
<charting:CategoryAxis Orientation="X" Title="The X Axis Title" />
</charting:Chart.Axes>
上面的第一个链接帮助我在Y轴上写标题。我添加了资源并将DependentRangeAxis属性设置为资源。因为我只能添加一个键;在这里,我对X&Y轴有不同的定义。如何为X轴设置相同的值??