我想在图例中显示带有反转值的图表控件(Pie2D)。
示例图片:
我的班级:
public class Foo
{
string Name {get; set;}
double Value { get; set; }
bool IsInverted { get; set; }
}
示例数据:
"First", 20.0, false
"Second, -20.0, true //display "20" in chart, and -20 in legend
谢谢! :)
答案 0 :(得分:1)
简单的方法是使用这样的类:
public class Foo
{
public string Name { get; set; }
public double Value { get; set; }
public string DiagramName { get { return string.Format("{0}: {1}", Name, Value); } }
public double DiagramValue { get { return Math.Abs(Value); } }
}
只需将参数和值数据成员绑定到DiagramName
和DiagramValue
,并确保所有模式都使用以下格式:
<SomeObject SomePattern="{}{A}" ... />
以下是示例:
0。 XAML:
<dx:DXWindow.Resources>
<dx:IEnumerableDataSource x:Key="IEnumerableDataSource">
<dx:DesignDataManager.DesignData>
<dx:DesignDataSettings DataObjectType="{x:Type local:Foo}" RowCount="5"/>
</dx:DesignDataManager.DesignData>
</dx:IEnumerableDataSource>
</dx:DXWindow.Resources>
<Grid>
<dxc:ChartControl x:Name="Chart" DataSource="{Binding Data, Source={StaticResource IEnumerableDataSource}}">
<dxc:ChartControl.Legend>
<dxc:Legend />
</dxc:ChartControl.Legend>
<dxc:ChartControl.Titles>
<dxc:Title Content="Pie Chart" HorizontalAlignment="Center"/>
</dxc:ChartControl.Titles>
<dxc:SimpleDiagram2D>
<dxc:PieSeries2D LabelsVisibility="True" ArgumentDataMember="DiagramName" ValueDataMember="DiagramValue" LegendTextPattern="{}{A}" ToolTipPointPattern="{}{A}">
<dxc:PieSeries2D.Label>
<dxc:SeriesLabel TextPattern="{}{A}" />
</dxc:PieSeries2D.Label>
</dxc:PieSeries2D>
</dxc:SimpleDiagram2D>
</dxc:ChartControl>
</Grid>
1。图表控制数据来源:
var list = new List<Foo>();
list.Add(new Foo() { Name = "A", Value = -20 });
list.Add(new Foo() { Name = "B", Value = 80 });
Chart.DataSource = list;
2。结果: