How to modify the label of Category Field in amCharts

岁酱吖の 提交于 2019-12-12 02:25:34

问题


I am using amCharts in my AngularJS application and I am looking for a way to rename the label of the category field. Following is my code:

var configChart = function () {
            employeeChart = new AmCharts.AmSerialChart();
            employeeChart.categoryField = "empId";

            var yAxis = new AmCharts.ValueAxis();
            yAxis.position = "left";
            employeeChart.addValueAxis(yAxis);

            mcfBarGraph = new AmCharts.AmGraph();
            mcfBarGraph.valueField = "employeeRating";
            mcfBarGraph.type = "column";
            mcfBarGraph.fillAlphas = 1;
            mcfBarGraph.lineColor = "#f0ab00";
            mcfBarGraph.valueAxis = yAxis;
            employeeChart.addGraph(empBarGraph);

            employeeChart.write('employee');


        }

In the above coode if you observe the categoryField is empId so on the x-axis it shows employee Id's, I want to make it "dept-empId". For example if the department number is 1, on the x-axis it show display 1-1,1-2 etc. The department Id is not in the data provider but is one of the scope variables in my controller. Could you let me know how I could achieve this.


回答1:


You can define a labelFunction in your chart object's categoryAxis to get the formatting you want.

var categoryAxis = employeeChart.categoryAxis;
categoryAxis.labelFunction = function(valueText) {
  return dept + '-' + valueText;
};

Here's a fiddle that uses your setup with some dummy data to illustrate this: https://jsfiddle.net/by7grqjm/2/



来源:https://stackoverflow.com/questions/38981370/how-to-modify-the-label-of-category-field-in-amcharts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!