开发者

How do you format in code AxisLabel for DependentRangeAxis?

开发者 https://www.devze.com 2023-03-16 06:00 出处:网络
I cannot get the axis to format as currency, any idea? What am I doing wrong?I need to be able to change the formatting on the fly and for this test I wanted to set it as currency for the Y axis on t

I cannot get the axis to format as currency, any idea?

What am I doing wrong? I need to be able to change the formatting on the fly and for this test I wanted to set it as currency for the Y axis on the scale of values.

Anyon开发者_Python百科e?

Thanks...

    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;


In my WPF4 version of the charting toolkit, your code crashes. I needed to change:

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

to:

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

That is, remove the {}. The {} comes from markup extension syntax:

  • {} Escape Sequence / Markup Extension

and is only needed when being parsed by XAML as a markup extension inside "{...}".

Since you are setting the property directly, no markup extension is involved and including it prevents the real currency format from being seen.

0

精彩评论

暂无评论...
验证码 换一张
取 消