ron.kagan Posted August 31, 2010 Report Share Posted August 31, 2010 Hi. I am creating a bar chart using this code : SeriesAttributes sa = new SeriesAttributes(); sa.BindingPath = "Y"; _myChart.AxisX.Labels.BindingPath = "X"; The item source is a clr object collection where the clr object has two properties - x (datetime) and y (double). The problem i am having that the labels on the x axis are always appear as dd MMM yy even when i change the _myChart.AxisX.Labels.CustomFormat to something different - this works fine when doing the same for a line chart, but not on a bar chart. Quote Link to comment Share on other sites More sharing options...
JuanC Posted August 31, 2010 Report Share Posted August 31, 2010 By default our bar chart does not support X values, the main reason for this is that in a line/area chart you can easily connect the points regardless of their spacing in X but a bar chart is typically drawn with all bars having the same width where your data points could be Jan 1, Jan 2, Jan 3, Feb 15. You can override this behavior by using the following code ChartFX.WPF.Galleries.Bar bar = (ChartFX.WPF.Galleries.Bar) chart1.AllSeries.GalleryAttributes;bar.XValues = true;bar.XWidth = new TimeSpan(24, 0, 0); Note that you can cast GalleryAttributes to Bar as long as the gallery property has already been set to Gallery.Bar. Also note that you have to specify the width of the bars which should normally be equal or smaller than the smallest distance between 2 points or you will get overlapping. JuanC Quote Link to comment Share on other sites More sharing options...
ron.kagan Posted September 1, 2010 Author Report Share Posted September 1, 2010 This method didn't work for me. I have tried a different approach - I have added a label property for my clr object, and set the label binding path to this property. however now i don't see any labels at all as before when i set the labels binding path to the 'X' property, I saw the labels but they were not formatted and only shown the date part of the the date time. What am i missing ? I was sure this would work as I simply assign a different property of string type to the axis x labels. Quote Link to comment Share on other sites More sharing options...
JuanC Posted September 1, 2010 Report Share Posted September 1, 2010 This works for me using the current bits chart1.Gallery = Gallery.Bar;ChartFX.WPF.Galleries.Bar bar = (ChartFX.WPF.Galleries.Bar) chart1.AllSeries.GalleryAttributes;bar.XValues = true;bar.XWidth = new TimeSpan(24, 0, 0);List<TestData> items = new List<TestData>();items.Add(new TestData() { Value = 10, Date = new DateTime(2009, 08, 24) });items.Add(new TestData() { Value = 12, Date = new DateTime(2009, 08, 25) });items.Add(new TestData() { Value = 9, Date = new DateTime(2009, 08, 28) }); SeriesAttributes series = new SeriesAttributes();series.BindingPath = "Value";series.BindingPathX = "Date";chart1.Series.Add(series); chart1.AxisX.Labels.Format = AxisFormat.Date;//chart1.AxisX.Labels.CustomFormat = "MM-dd"; chart1.ItemsSource = items; You can also uncomment the CustomFormat if you need to fine tune the labels. JuanC Quote Link to comment Share on other sites More sharing options...
JuanC Posted September 1, 2010 Report Share Posted September 1, 2010 I just noticed in your original post, you were using AxisX.Labels.Binding, you should only do this if you want to bind the axis X labels as strings. JuanC Quote Link to comment Share on other sites More sharing options...
ron.kagan Posted September 2, 2010 Author Report Share Posted September 2, 2010 Hi there. I'm still having many problems with this approach. My span can vary berween day, week , month etc... When the span is day it look great, but on other variants, setting the step to be the XWidth of the bar to be the span (week = 7 days, month = 30 days) it looks wrong, the bars and the step don't match, the labels appear not on the ticks as it should and it just not working. I am still not sure why doing what i did with the string labels (persuming i make sure all the dates are consecutive and if there is a gap i make sure to fill it with a zero value point) 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.