bskidan Posted November 4, 2009 Report Share Posted November 4, 2009 I'm trying to provide my own DataTemplate for AxisY labels. This works for AxisX but not for AxisY. Does this even suppose to work? <cfx:Chart Name="_dataChart"> <cfx:Chart.Series> <cfx:SeriesAttributes BindingPath="SeriesA" Content="Series A" Gallery="Area"> <cfx:SeriesAttributes.AxisY> <cfx:Axis> <cfx:Axis.Template> <DataTemplate> <TextBlock Text="{Binding DataItem.SeriesA, StringFormat='#,0.##'}" /> </DataTemplate> </cfx:Axis.Template> </cfx:Axis> </cfx:SeriesAttributes.AxisY> </cfx:SeriesAttributes> </cfx:Chart.Series> <cfx:Chart.AxisX> <cfx:Axis> <cfx:Axis.Template> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="On " /> <TextBlock Text="{Binding DataItem.Timestamp, StringFormat=d}" /> </StackPanel> </DataTemplate> </cfx:Axis.Template> </cfx:Axis> </cfx:Chart.AxisX></cfx:Chart>Thanks. Quote Link to comment Share on other sites More sharing options...
JuanC Posted November 4, 2009 Report Share Posted November 4, 2009 This is by design. In the case of the X axis we do have a CLR object to give you as the data for your template but not in the Y axis. Note that in the same chart you could show different Y axis labels just by resizing although the data remains the same. To control the formatting you can use AxisY.Labels.Format, AxisY.Labels.Decimals and/or AxisY.Labels.CustomFormat. JuanC Quote Link to comment Share on other sites More sharing options...
bskidan Posted November 5, 2009 Author Report Share Posted November 5, 2009 Thanks for your prompt reply. The reason I wanted templates is to attach converter to format labels the way I would like them to look. I work with financial data and my values range varies from one set of data to another and can be in tens or hundreds of thousands, or millions, or tens of millions. A simple currency format displays something like $10,000,000, which is too long. I tried to play around with ScaleUnit and CustomFormat and came up with something like this: <cfx:AxisLabelAttributes ScaleUnit="1000000" CustomFormat="$#,0.##M;($#,0.##M)"/> This displays labels like $5M and ($2M), but steps them in 1M increments. So now I have to set Axis.Step, which I have to calculate, thus duplicating logic already implemented in your control. Also 'M' is not always appropriate and sometimes should be set to 'K'. What I really need is to apply dynamic format that depends on the value only for those labels that the control decides to display in a default scenario. Ideally the resulting labels will read $0, $200K, ..., $1M, $1.2M. Any ideas? Thanks. Quote Link to comment Share on other sites More sharing options...
JuanC Posted November 5, 2009 Report Share Posted November 5, 2009 You can get the labels you need by handling the Axis.GetLabel event as follows chart1.AxisY.GetLabel += new AxisLabelEventHandler(OnAxisYLabel); private void OnAxisYLabel (object sender, AxisLabelEventArgs e) { double d = e.Value; string format; if (d >= 1000000) { format = "$#,0.##M"; d /= 1000000; } else if (d >= 1000) { format = "$#,0.##K"; d /= 1000; } else format = "$#,0.##"; e.Text = d.ToString(format); } JuanC Quote Link to comment Share on other sites More sharing options...
bskidan Posted November 5, 2009 Author Report Share Posted November 5, 2009 JuanC, Thank you very much. This is exactly what I was looking for. 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.