Avoid auto stack when adding points with the same x name

I need to produce a column chart like this:




As you can see, it has repeated names in X axis: down, up, down, up, etc...


Nevertheless, when I add the points to the series, the graphic automatically stacks them:



How to avoid this behavior and let each point represent a different column?


Best,

Rodrigo


3 Replies

GM Gayathri Manickam Syncfusion Team January 21, 2022 03:05 PM UTC

Hi Rodrigo, 
 
We have analyzed your query and achieved your requirement by using Indexed property in chart and SortPoints as false in series with adding custom labels in axis as per the below code snippet. 
 
            this.chartControl1.PrimaryXAxis.ValueType = ChartValueType.Custom; 
            
            BindingList<SalesData> dataSource = new BindingList<SalesData>(); 
            dataSource.Add(new SalesData("down", -39.6348)); 
            dataSource.Add(new SalesData("up", -61.405)); 
            dataSource.Add(new SalesData("down", -23.281)); 
            dataSource.Add(new SalesData("up", -39.223)); 
            dataSource.Add(new SalesData("down", 24.2998)); 
            dataSource.Add(new SalesData("up", 59.0369)); 
... 
            ChartSeries chartSeries = new ChartSeries("Sales"); 
            chartSeries.SortPoints = false; 
            this.chartControl1.Indexed = true; 
            ChartDataBindAxisLabelModel dataLabelsModel = new ChartDataBindAxisLabelModel(dataSource); 
            dataLabelsModel.LabelName = "Year"; 
            this.chartControl1.Series.Add(chartSeries); 
            this.chartControl1.PrimaryXAxis.LabelsImpl = dataLabelsModel; 
            this.chartControl1.PrimaryXAxis.CustomLabelsParameter = ChartCustomLabelsParameter.Position; 
  
For more information, please refer below UG link. 
 
Please download the sample from the below location and let us know if you have any other queries. 
 
 
Regards,  
Gayathri M 



RO Rodrigo January 21, 2022 08:08 PM UTC

Thanks a lot!

It worked great!



GM Gayathri Manickam Syncfusion Team January 24, 2022 06:38 AM UTC

Hi Rodrigo, 
 
We glad that the provided solution works at your end. Please let us know if you need any further assistance. 
 
Regards,  
Gayathri M 


Loader.
Up arrow icon