Hi, i have data that i would like to display one a chart using a StackingColumnSeries. However, when i display the data, each series is repeated vertically as shown below. I have also included the code that i use to dynamically generate each series.
foreach (var customDataItem in customDataItems)
{
foreach (var item in customDataItem.Values)
{
if (item.Key.Equals("ApprovalNumber", StringComparison.InvariantCultureIgnoreCase)) continue;
var series = new StackingColumnSeries()
{
ItemsSource = customDataItems,
XBindingPath = "ApprovalNumber",
YBindingPath = item.Key,
//SegmentSpacing = 0.5,
Label = item.Key,
Interior = _meterModelBrushes.GetValueOrDefault(item.Key)
};
Series.Add(series);
}
}
Hi Arlvin,
seems to me you are creating many series all with the same ItemsSource with all data, I think your ItemsSource should be
Item and not customDataItems if you want one stack for each Item. Also XBindingPath and YBindingPath I think should be inverted if for each item.Key (string) you want to see "ApprovalNumber" (numeric?) value.
My 2 cents
Fabrizio
Hi Arlvin,
I think you need to use a CategoryAxis for X-Axis so you should get each separated value.
bye
Fabrizio
Hi Fabrizio,
Thank you for your reply. I have tried before making "item" the ItemsSource and i do get a better result (shown below). The problem then becomes that i lose the 5 distinct labels along the X-axis. The resulting chart has a "continuous" set of values along the X-axis. I would like to have the distinct X-axis values at the points labelled A, B, C, and D. Also, after D there should be another series, but because the "ApprovalNumber" values for D and E are so close, they now overlay each other and you can only see a tiny part of the last series, labelled as E.
Above, i have set the X-axis to be a NumericalAxis. When i change it to a CategoryAxis the desired, distinct X-axis values are concatenated into a coma-separated string as shown below:
I have edited the post to add the result of changing the Z-axis to a CategoryAxis, i.e. it joins the labels as a coma-separated string.
Category are meant to show text values, maybe this is the problem, sorry but I don't know how to help more.
Good luck
Fabrizio
I will try that, i.e. making the axis values explicit strings. Thank-you for your help.
<chart:SfChart.PrimaryAxis>
<chart:CategoryAxis IsIndexed="False"/>
</chart:SfChart.PrimaryAxis> |
var collectionItems = (this.DataContext as ViewModel).Data;
foreach(var item in collectionItems)
{
var series = new StackingColumnSeries()
{
ItemsSource = item.ChartData,
XBindingPath = "XValue",
YBindingPath = "Value"
};
chart.Series.Add(series);
} |
Thank you so much Yuvaraj, that works perfectly!