如何为amChart设置x轴和y轴名称的标题?

时间:2015-11-04 06:51:41

标签: javascript amcharts

在amChart中,如何为图表的X轴和Y轴标题设置自定义名称(字符串)?

(水平轴和垂直轴)

var chart = AmCharts.makeChart( "chartdiv", {
  "type": "xy",
  "pathToImages": "http://www.amcharts.com/lib/3/images/",
  "dataProvider": chartData,
  "mouseWheelZoomEnabled": true,
  "graphs": [ {
    /*"bullet": "circle",
    "bulletSize": 8,*/
    "lineAlpha": 1,
    "lineThickness": 2,
    "fillAlphas": 0,
    "xField": "x",
    "yField": "y",
  } ],
} );

1 个答案:

答案 0 :(得分:2)

您可以为每个轴使用title参数。但是,您需要将valueAxes定义添加到图表配置中。即使它们只包含title参数。

var chart = AmCharts.makeChart( "chartdiv", {
  "type": "xy",
  "pathToImages": "http://www.amcharts.com/lib/3/images/",
  "dataProvider": chartData,
  "mouseWheelZoomEnabled": true,
  "graphs": [ {
    /*"bullet": "circle",
    "bulletSize": 8,*/
    "lineAlpha": 1,
    "lineThickness": 2,
    "fillAlphas": 0,
    "xField": "x",
    "yField": "y",
  } ],
  "valueAxes": [ {
    "position": "left",
    "title": "Y axis"
  }, {
    "position": "bottom",
    "title": "X axis"
  } ]
} );