How to make the chart X axis as string format

I used the following code:

chartModel.Title = new ChartTitle() {Text=chartName };
            Series series = new Series();
            series.Name = "UnMarked";
            series.Fill = "#49a3ed";
            series.EnableAnimation = true;
            series.Marker.DataLabel.Visible = true;
            series.Marker.DataLabel.Font = new ChartFont() {Color= "#ffffff"};
            series.Marker.DataLabel.TextPosition = Syncfusion.JavaScript.DataVisualization.TextPosition.Middle;
            series.Type = Syncfusion.JavaScript.DataVisualization.SeriesType.StackingColumn;
            series.VisibleOnLegend = Syncfusion.JavaScript.DataVisualization.VisibleOnLegend.Visible;
            foreach (var item in ls)
            {

                Points topuser = new Points();
                topuser.X = item.Id;
                
                topuser.Y = item.ReplyCount - item.AcceptCount;

                series.Tooltip.Visible = true;
                series.Points.Add(topuser);

            }
            chartModel.Series.Add(series);


But the chart will think the X axis is numeric value, then it will show strangely.  See Screenshot

I just want to make the X axis show as a normal string value.

1 Reply

BP Baby Palanidurai Syncfusion Team May 31, 2018 03:44 AM UTC

Hi Xavier, 

Thanks for using syncfusion products, 

     We have analyzed your query. By default, chart chooses the axis based on the data passed to it. We suspect that the x value passed for chart(topuser.X = item.Id;) is of type numeric, so that the chart renders with numeric axis. If you wish to use category axis, you can set category in the valueType property in axis. 

For more information on category axis, kindly find the help document 

Please find the below code snippet to use axis labels in string formats. 

<ej-chart id="container"> 
            <e-primary-x-axis value-type="@AxisValueType.Category"> 
           </e-primary-x-axis> 
        ... 
</ej-chart> 


Screenshot:  
 

Sample for your reference can be find from below link, 
 https://www.syncfusion.com/downloads/support/forum/137823/ze/xAxisString-core884959223 
If you have any concern,  Kindly revert us. 

Thanks, 
Baby. 


Loader.
Up arrow icon