Syncfusion Blazor Column Chart - How to preserve X Axis Category Order

Check out this runnable sample for this question:

https://blazorplayground.syncfusion.com/hZBIZlDoQitCxdOp

I'm using data where Date-AM/PM is already sorted:

    private List<DataPoint> ChartPoints = new()
    {
        // Only Alpha has "08/05-AM"
        new DataPoint("08/05-AM", "Alpha", 10),
        new DataPoint("08/05-PM", "Gamma", 12),
        new DataPoint("08/05-PM", "Beta", 15),
        new DataPoint("08/05-PM", "Alpha", 20),

        // All series have "08/06-PM"
        new DataPoint("08/06-PM", "Gamma", 22),
        new DataPoint("08/06-PM", "Beta", 25),
        new DataPoint("08/06-PM", "Alpha", 30),

        // Only Beta and Gamma have "08/07-AM"
        new DataPoint("08/07-AM", "Gamma", 32),
        new DataPoint("08/07-AM", "Beta", 35),
    };


Each series uses a filtered data source: DataSource="@ChartPoints.Where(p => p.Series == info.Name).

Expected:

• X-axis should always be in the order: "08/05-AM", "08/05-PM", "08/06-PM", "08/07-AM", regardless of which series have data for each category.

Actual:

• If the first series in the loop is missing "08/05-AM", "08/05-AM" appears at the end of the axis.

Image_7152_1754423392376

How can I ensure the X-axis order is consistent, even when some series are missing values for some categories?

Thank you.


3 Replies 1 reply marked as answer

AR AbubuckerSittiq RajaMohamed Syncfusion Team August 6, 2025 10:25 AM UTC

Hi Ashish,

We have thoroughly analyzed the scenario you reported and would like to clarify that the behavior you observed is the default functionality of chart series when using a category axis. Specifically, this behavior occurs because each series is configured to utilize a filtered data source. For instance, in your case, the data source is defined as follows: DataSource="@ChartPoints.Where(p => p.Series == info.Name)". Based on this configuration, the chart series is rendered using the assigned category values accordingly.

If you have any further questions or require additional clarification, please do not hesitate to reach out to us. We would be happy to assist you further.

Regards,

Abubucker Sittiq R



AK Ashish Khanal August 7, 2025 11:16 PM UTC

Hi Abubucker,

Thank you for your response.

I want to express my disappointment with the level of support provided here. As a paying customer, I expect not just an explanation of "default behavior," but also guidance or workarounds when I encounter limitations or unexpected results with Syncfusion controls. 

We both can agree that I can't put that chart in production if the dates are mismatched from the get-go. 

So, I came here seeking help and guidance on how to make it right and hearing "it is what it is" was not helpful.


In this case, I was able to find a solution myself, but it would have been much more helpful if you or your team had suggested it or at least pointed me in the right direction.


Solution for anyone else facing this issue:

To preserve the X-axis category order in a grouped column chart, you must ensure that every series has a data point (even if the value is null) for every category you want to appear on the axis. If a series is missing a data point for a category, that category may be rendered out of order or at the end.


Just changing the data like below fixes the issue:

    private List<DataPoint> ChartPoints = new()
    {
        // All series have a data point for each category (use null for missing values)
        new DataPoint("08/05-AM", "Gamma", null),
        new DataPoint("08/05-AM", "Beta", null),
        new DataPoint("08/05-AM", "Alpha", 10),

        new DataPoint("08/05-PM", "Gamma", 12),
        new DataPoint("08/05-PM", "Beta", 15),
        new DataPoint("08/05-PM", "Alpha", 20),

        // All series have "08/06-PM"
        new DataPoint("08/06-PM", "Gamma", 22),
        new DataPoint("08/06-PM", "Beta", 25),
        new DataPoint("08/06-PM", "Alpha", 30),

        // Only Beta and Gamma have "08/07-AM"
        new DataPoint("08/07-AM", "Gamma", 32),
        new DataPoint("08/07-AM", "Beta", 35),
        new DataPoint("08/07-AM", "Alpha", null),
    };


This ensures the X-axis order is preserved as intended.

Image_8613_1754607876753


I hope Syncfusion can improve its support so it's easier to justify using it in our new projects.


Marked as answer

DG Durga Gopalakrishnan Syncfusion Team August 8, 2025 11:55 AM UTC

Ashish,


We’d like to clarify the behavior of the category axis in the chart. Based on the code snippet you shared, the first series being rendered is the Gamma series. As a result, the first data point of this series—"08/05-PM"—is assigned to index 0. Since there is no data point for "08/05-AM" in the Gamma series, it is not considered as first point.


If you wish to include missing data points and represent them with null values, we recommend assigning these values programmatically in the OnInitialized method rather than directly in the data source. This approach ensures consistent indexing and rendering behavior.


For your reference, we’ve attached a modified sample demonstrating this setup.


protected override void OnInitialized()

{

     // Step 1: Define desired X-axis order

     CategoryOrder = new List<string>

{

     "08/05-AM",

     "08/05-PM",

     "08/06-PM",

     "08/07-AM"

};

 

     // Step 2: Fill missing values with null

     foreach (var category in CategoryOrder)

     {

         foreach (var series in SeriesInfos)

         {

             if (!ChartPoints.Any(p => p.Category == category && p.Series == series.Name))

             {

                 ChartPoints.Add(new DataPoint(category, series.Name, null));

             }

         }

     }

 

     // Step 3: Sort the data according to CategoryOrder and SeriesInfos order

     ChartPoints = ChartPoints

         .OrderBy(p => CategoryOrder.IndexOf(p.Category))

.ThenBy(p => SeriesInfos.First(s => s.Name == p.Series).Order)

         .ToList();

}

 



Sample : https://blazorplayground.syncfusion.com/BDrItFtFUOJSMAhB


Please let us know if you have any concerns.


Loader.
Up arrow icon