beltrams Posted March 5, 2011 Report Share Posted March 5, 2011 Dear Forum, I am tring to format the number in the axis Y as follow -1000 < number < 1000: normal number 2 decimal places (10, -88, -674.23, 999.29) -1 000 000 < number <-1000 and 1000< number < 1000 000: "K at the end" ( 1400 = 1.40K, 98726 = 98.72K, and so on) number <= -1000 000 and number >= 1000 000: "M at the end" ( ( 1400000 = 1.40M, 98726000 = 98.72M, and so on)) I was able to do this with code behind and handling the GetLabels event event but unfortunatelly I cannot use it as I have a datatemplate with no code behind. I have also tried to add the GetLabels event handler with attached behaviour (this would be accettable for me) but for some reason the event is not fired or not hadled in that case. Can I specify a template for those numbers or Can you suggest me any approach? Thanks, Simone Quote Link to comment Share on other sites More sharing options...
JuanC Posted March 7, 2011 Report Share Posted March 7, 2011 Unfortunately the only way to achieve the formatting you are looking for is to handle the GetLabels event which means you will have to wire this event. I have not tried to do this with an attached behaviour so if you can post a small sample we can check why the event does not get fired/handled. This is a feature we have also implemented in other products so we will check if we can include support for this in 8.1 through a new member in the AxisFormat enumeration. The only issue with K/M abbreviations is whether we can support this in a localization-friendly manner. Other languages might use different prefixes/suffixes or different threholds. JuanC Quote Link to comment Share on other sites More sharing options...
beltrams Posted March 7, 2011 Author Report Share Posted March 7, 2011 Thanks, Please find attached a demo app with the attached behaviour. Simone Quote Link to comment Share on other sites More sharing options...
JuanC Posted March 7, 2011 Report Share Posted March 7, 2011 The problem is related to timing in the XAML parsing, because you are setting your attached property in the chart object, this is parsed first and your handler gets attached to the AxisY.GetLabel event, later a new AxisY is created and set which means this new axis will never fire the event. I modified your XAML/Code as follows MyChartView.xaml <cfx:Chart Gallery="Line" x:Name="WidgetChart" ItemsSource="{Binding Path=MyData2, Mode=OneWay}" MinWidth="200" MinHeight="320"> <cfx:Chart.AxisY> <cfx:Axis vm:ChartFxNumerQuickFormatBehaviour.ChartFxNumerQuickFormat="True" ForceZero="False" > ChartFxNumerQuickFormatBehaviour.cs private static void OnChartFxNumerQuickFormatPropertyChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs args){ // chart = dpo as Chart; // Axis axisY = chart.AxisY; Axis axisY = dpo as Axis; if (dpo == null) return; if (args.NewValue is bool == false) return; if ((bool)args.NewValue) axisY.GetLabel += new AxisLabelEventHandler(OnAxisYLabel); else axisY.GetLabel -= new AxisLabelEventHandler(OnAxisYLabel); } Regards, JuanC Quote Link to comment Share on other sites More sharing options...
beltrams Posted March 7, 2011 Author Report Share Posted March 7, 2011 Many thanks! I will try it tomorrow. Simone Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.