当Chart中有两个及以上的Y轴时,我们就要指明图表中的柱子或折线对应的是哪个Y轴了,这时候需要指明柱子或者折线的dxc:XYDiagram2D.SeriesAxisY属性,来设置对应的Y轴(dxc:XYDiagram2D.SeriesAxisY="{Binding ElementName=y2}"),其中Binding的ElementName就是需要对应的Y轴的Name(即这里的y2),界面代码如下:
<dxc:ChartControl DataSource="{Binding SaleAmountAnalysisList}"> <dxc:XYDiagram2D x:Name="diagram1" SeriesDataMember="Gross"> <dxc:XYDiagram2D.SecondaryAxesY> <dxc:SecondaryAxisY2D x:Name="y2"> <dxc:SecondaryAxisY2D.Title> <dxc:AxisTitle Content="单位(万)"></dxc:AxisTitle> </dxc:SecondaryAxisY2D.Title> </dxc:SecondaryAxisY2D> </dxc:XYDiagram2D.SecondaryAxesY> <dxc:XYDiagram2D.AxisY> <dxc:AxisY2D x:Name="firstY"> <dxc:AxisY2D.Title> <dxc:AxisTitle Content="单位(千)" /> </dxc:AxisY2D.Title> </dxc:AxisY2D> </dxc:XYDiagram2D.AxisY> <dxc:XYDiagram2D.AxisX> <dxc:AxisX2D /> </dxc:XYDiagram2D.AxisX> <!--默认情况下都是参考的左边的Y轴--> <!--销售提成--> <dxc:BarSideBySideSeries2D LabelsVisibility="true" ArgumentDataMember="Name" ValueDataMember="Gross"> </dxc:BarSideBySideSeries2D> <!--单均毛利--> <dxc:BarSideBySideSeries2D LabelsVisibility="true" ArgumentDataMember="Name" ValueDataMember="AveGross"> </dxc:BarSideBySideSeries2D> <!--贡献毛利润,通过设置LineSeries2D的dxc:XYDiagram2D.SeriesAxisY来指定该折线是参考右边的Y轴的--> <dxc:LineSeries2D LabelsVisibility="True" dxc:XYDiagram2D.SeriesAxisY="{Binding ElementName=y2}" ArgumentDataMember="Name" ValueDataMember="Royalty"> </dxc:LineSeries2D> </dxc:XYDiagram2D> </dxc:ChartControl>
通过上面代码的绑定方式的结果如下图所示:
时间: 2024-10-06 18:23:57