We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Customizing the axis labels

Hi,

Can I customize the axis labels to string rather than number?

1 Reply

DD Dharanidharan Dharmasivam Syncfusion Team March 8, 2017 01:06 PM UTC

Hi Santhosh, 
 
Thanks for contacting Syncfusion support. 
 
We have analyzed your query. As of now we can use category axis for primaryXAxis , in which you can specify the values in string format and so that you can deal with text in x axis labels. Find the code snippet below. 
 
ASP.NET MVC: 
 
@(Html.EJ().Chart("container") 
        .PrimaryXAxis(pr=>pr.ValueType(AxisValueType.Category)) 
       .Series(ser => 
              { 
                  ser.Points(po => 
                      { 
                          po.X("USA").Y(0).Add(); 
                          po.X("China").Y(1).Add(); 
                          po.X("Japan").Y(2).Add(); 
                          po.X("Australia").Y(3).Add(); 
                          po.X("France").Y(4).Add();                       
                    }).Add(); 
              }) 
//... 
) 
 
Screenshot:  
 
For more information on category axis, follow the below link. 
 
Y axis will render with numeric values only, so your requirement can be achieved as work around by using AxesLabelRendering event. In this we can able to customize the axis labels. Also, you need to specify the range to y axis, so that we can consider the labels as indexes and can bind the desired text. In this sample we have specified values for min, max, interval as 0, 4 and 1 respectively. Find the code snippet below. 
 
[CSHTML] 
 
@(Html.EJ().Chart("container") 
.PrimaryYAxis(py=>py.Range(ra=>ra.Interval(1).Min(0).Max(4))) 
.AxesLabelRendering("axesLabels") 
//... 
 
) 
 
window.count = 0; 
    function axesLabels(sender) { 
        if (sender.data.axis.orientation == "vertical") { 
            var yLabels = ["label 1", "label 2", "label 3", "label 4", "label 5"]; 
            sender.data.label.Text = yLabels[window.count]; 
            window.count++; 
            if (window.count == 5) window.count = 0; 
        } 
    } 
 
Screenshot: 
 
Sample for reference can be find from below link. 
 
Thanks, 
Dharani. 


Loader.
Live Chat Icon For mobile
Up arrow icon