0

我在我的 AngularJS 应用程序中使用 amCharts,我正在寻找一种方法来重命名类别字段的标签。以下是我的代码:

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');


        }

在上面的代码中,如果您观察到 categoryField 是 empId,那么在 x 轴上它会显示员工 ID,我想将其设为“dept-empId”。例如,如果部门编号为 1,则在 x 轴上显示 1-1,1-2 等。部门 ID 不在数据提供者中,而是我的控制器中的范围变量之一。你能告诉我我怎么能做到这一点。

4

1 回答 1

0

您可以在图表对象的 categoryAxis 中定义一个labelFunction以获得您想要的格式。

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

这是一个使用您的设置和一些虚拟数据来说明这一点的小提琴:https ://jsfiddle.net/by7grqjm/2/

于 2016-08-16T23:36:25.040 回答