自定义 DevExpress 图表控件 - 图例中的反转值

Customize DevExpress chart control - inverted value in legend

我想在图例中显示具有反转值的图表控件 (Pie2D)。

示例图片:

我的Class:

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

谢谢! :)

简单的方法是像这样使用class:

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); } }
}

只需将参数和值数据成员绑定到 DiagramNameDiagramValue 并确保您所有的模式都使用此格式:

<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。结果: