0

Is there any possibility of showing more than one label in the category axis? I need to show two fields from my data source in my category axis(And,yes there is no multi category axis. I need to show multiple fields on the same category axis. Please help if I'm missing out searching for any related topic. Thanks in advance.

  • Welcome to Stackoverflow. Share the code you have tried yet. – Nagama Inamdar Sep 12 '15 at 16:51
  • categoryAxis: { field: "year", labels: { rotation: -90 } }, Sorry for not putting whole code. I am new to this stack over flow,couldnt comment whole code. I just need to get another field in this category axis. named , 'Group' like that of year, and both should be visible in the category axis. – Praveen Joshi Sep 12 '15 at 16:59
  • 1
    You can use label templates in the category axis: http://dojo.telerik.com/@ezanker/etoNO – ezanker Sep 14 '15 at 14:15
  • @ezanker thanks alot. That helped me a bit of it. But the dates aren't in the format like \n in the datasource. So i would like to split the date and use the hours and mins in the next line. I hope u understood. Thanks for this though :) – Praveen Joshi Sep 14 '15 at 16:27

2 Answers2

1

You can use label templates on the categoryAxis labels:

    categoryAxis: {
      field: 'submitTime',
      majorGridLines: {
        visible: false
      },
      labels: {
         visible: true,
          template: ' #= FormatLabel(dataItem) # '
        }
    },

In this example the template is passing the dataItem to a function which builds the desired string:

function FormatLabel(dataItem){
  var tg = dataItem.TargetGroup;
  var st = dataItem.submitTime.replace(" ", "\n");
  return tg + "\n" + st;      
}

DEMO

ezanker
  • 24,628
  • 1
  • 20
  • 35
0

In your series, you can define the template on the label to display pretty much anything you want from the item it is bound to.

series: [ 
      { 
        field: 'totalVisits', 
        name: 'Total Visits',  
        labels: {
          visible: true,
          template: ' #= dataItem.month # \n Total Visits : #= dataItem.totalVisits # \n Unique Visitors : #= dataItem.uniqueVisitors # '
        }
      }
    ],

See working sample at Kendo Dojo

If you need a bit more functionality, you can set that template to a function, and return whatever you want from it.

series: [ 
      { 
        field: 'totalVisits', 
        name: 'Total Visits',  
        labels: {
          visible: true,
          template: chartSeriesTemplate
        }
      }
   ],

function chartSeriesTemplate(e) {
      return kendo.format("{0} \n Total Visits:{1}\n Unique Visitors:{2} \n Ratio :{3}", e.dataItem.month, e.dataItem.totalVisits, e.dataItem.uniqueVisitors, (parseInt(e.dataItem.uniqueVisitors) / parseInt(e.dataItem.totalVisits)).toFixed(2));
    }

See working sample at Kendo Dojo

Documentation for series template at Kendo Docs

Robin Giltner
  • 3,057
  • 2
  • 18
  • 26
  • I'm afraid thats not what i meant. I already proposed my team in using series label template. But they need multiple labels in the category axis. Here is the image of how they need. 'All meters' is the value of one of the field and date is another field. I need to display both. I hope you understand the problem. Thanks :) – Praveen Joshi Sep 13 '15 at 05:15
  • Gitner sorry for not tagging – Praveen Joshi Sep 13 '15 at 08:18