Unable to display data on chart that is generated dynamically

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.

RepeatedSeriesData.png

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);

}

}



9 Replies 1 reply marked as answer

FF Fabrizio Frigerio August 4, 2021 06:59 AM UTC

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



FF Fabrizio Frigerio replied to Arlvin August 4, 2021 07:38 AM UTC


Hi Arlvin,

I think you need to use a CategoryAxis for X-Axis so you should get each separated value.


bye 

Fabrizio



AR Arlvin August 4, 2021 07:39 AM UTC

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.

RepeatedSeriesData-Modified.png

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:

RepeatedSeriesData-Modified-CategoryAxis.png



AR Arlvin replied to Fabrizio Frigerio August 4, 2021 07:47 AM UTC

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.



FF Fabrizio Frigerio replied to Arlvin August 4, 2021 08:11 AM UTC

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



AR Arlvin replied to Fabrizio Frigerio August 4, 2021 08:43 AM UTC

I will try that, i.e. making the axis values explicit strings. Thank-you for your help.



YP Yuvaraj Palanisamy Syncfusion Team August 4, 2021 03:36 PM UTC

Hi Arlvin,

Greetings from Syncfusion.

@Fabrizio – Thanks for your update.
 
 
We have analyzed your query and we can achieve your requirement “Dynamically add stacking column series with nested collection of datapoints for Category axis” with the help of IsIndex property of CategoryAxis. Please find the code example below.

CodeSnippet:
 
<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); 
}             
Also, we have attached the sample for your reference, please find the sample from the below link. 
 
  
Output: 
 
 
Regards, 
Yuvaraj. 


Marked as answer

AR Arlvin August 4, 2021 09:15 PM UTC

Thank you so much Yuvaraj, that works perfectly!



YP Yuvaraj Palanisamy Syncfusion Team August 5, 2021 04:45 AM UTC

Hi Arlvin, 

Thank you for your update.

Please let us know if you have any concern. 

Regards, 
Yuvaraj. 


Loader.
Up arrow icon