如何在amCharts中修改类别字段的标签 [英] How to modify the label of Category Field in amCharts

查看:272
本文介绍了如何在amCharts中修改类别字段的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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


        }

在上面的代码中,如果您观察到categoryField是empId,则在x轴上显示的是员工ID,我想将其设置为"dept-empId".例如,如果部门编号为1,则在x轴上显示1-1,1-2等.部门ID不在数据提供程序中,而是控制器中的作用域变量之一.您能告诉我如何实现这一目标吗?

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.

推荐答案

您可以定义图表对象的categoryAxis中的labelFunction 即可获取所需的格式.

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;
};

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

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

这篇关于如何在amCharts中修改类别字段的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆