nitefrog
nitefrog

Reputation: 1830

How do you format in code AxisLabel for DependentRangeAxis?

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.

Anyone?

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;

Upvotes: 2

Views: 1848

Answers (1)

Rick Sladkey
Rick Sladkey

Reputation: 34250

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:

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.

Upvotes: 3

Related Questions