如何在代码AxisLabel中为DependentRangeAxis格式化?

时间:2011-06-29 03:43:49

标签: wpf axis2 charts wpftoolkit

我不能让轴格式化为货币,任何想法?

我做错了什么?我需要能够动态更改格式,对于此测试,我想在值的范围内将其设置为Y轴的货币。

任何?

...谢谢

    var columnSeries = new ColumnSeries
                                 {   Title = reportProcedureNode.Value,
                                     IndependentValuePath = "PrimaryKey",
                                     DependentValuePath = "Value",
                                     IndependentAxis = new CategoryAxis { Orientation = AxisOrientation.X, ShowGridLines = false, Location = AxisLocation.Bottom},
                                     DependentRangeAxis = new LinearAxis(){Orientation = AxisOrientation.Y, ShowGridLines = false}
                                 };

        var labelStyle = new Style(typeof(AxisLabel));
        labelStyle.Setters.Add(new Setter(AxisLabel.StringFormatProperty, "{}{0:C0}"));

        var axis = (LinearAxis)columnSeries.DependentRangeAxis;
        axis.AxisLabelStyle = labelStyle;

1 个答案:

答案 0 :(得分:3)

在我的WPF4版本的图表工具包中,您的代码崩溃了。我需要改变:

labelStyle.Setters.Add(new Setter(AxisLabel.StringFormatProperty, "{}{0:C0}"));

为:

labelStyle.Setters.Add(new Setter(AxisLabel.StringFormatProperty, "{0:C0}"));

即删除{}{}来自标记扩展语法:

仅在被XAML解析为"{...}"内的标记扩展时才需要。

由于您直接设置了该属性,因此不涉及标记扩展,包括它会阻止看到真实货币格式。