amcharts示例

1.竖向双Y轴柱状图

核心代码:

var amOptions = {
   "type": "serial",
   "theme": "light",
   "legend": {
      "horizontalGap": 0,
      "maxColumns": 1,
      "position": "right",
      "useGraphSettings": true,
      "markerSize": 10,
      'fontSize': 24,
   },
   "dataProvider": data,
   "valueAxes": [
      {
         "id":"v1",
         "stackType": "100%",
         "axisAlpha": 0.3,
         "gridAlpha": 0,
         'fontSize': 24,
         'autoGridCount': false,
         'gridCount': 0,
         "guides": [
            {
               "label": '0',
               "value": '0',
               "toValue": '0'
            },

            {
               "label": '20%',
               "value": '20',
               "toValue": '20'
            },
            {
               "label": '40%',
               "value": '40',
               "toValue": '40'
            },
            {
               "label": '60%',
               "value": '60',
               "toValue": '60'
            },
            {
               "label": '80%',
               "value": '80',
               "toValue": '80'
            },
            {
               "label": '100%',
               "value": '100',
               "toValue": '100'
            }
         ]
      },
      {
         "id":"v2",
         "stackType": "100%",
         "axisAlpha": 0.3,
         "gridAlpha": 0,
         'fontSize': 24,
         'autoGridCount': false,
         'gridCount': 0
      }
   ],
   "graphs": [
      {
         "balloonText": "<b>[[title]]</b><br><span style='font-size:24px'>[[category]]: <b>[[value]]</b></span>",
         "fillAlphas": 0.8,
         "labelText": "[[value]]%",
         "lineAlpha": 0.3,
         'lineColor': '#f79646',
         "title": "A",
         "type": "column",
         "color": "#000000",
         'fontSize': 16,
         'valueAxis': 'v1',
         "valueField": "A"
      },
      {
         "balloonText": "<b>[[title]]</b><br><span style='font-size:24px'>[[category]]: <b>[[value]]</b></span>",
         "fillAlphas": 0.8,
         "labelText": "[[value]]%",
         "lineAlpha": 0.3,
         'lineColor': '#ffcc00',
         "title": "B",
         "type": "column",
         "color": "#000000",
         'fontSize': 16,
         'valueAxis': 'v1',
         "valueField": "B"
      },
      {
         "balloonText": "<b>[[title]]</b><br><span style='font-size:24px'>[[category]]: <b>[[value]]</b></span>",
         "fillAlphas": 0.8,
         "labelText": "[[value]]%",
         "lineAlpha": 0.3,
         'lineColor': '#4bacc6',
         "title": "C",
         "type": "column",
         "color": "#000000",
         'fontSize': 16,
         'valueAxis': 'v1',
         "valueField": "C"
      },
      {
         "balloonText": "<b>[[title]]</b><br><span style='font-size:24px'>[[category]]: <b>[[value]]</b></span>",
         "fillAlphas": 0.8,
         "labelText": "[[value]]%",
         "lineAlpha": 0.3,
         'lineColor': '#558ed5',
         "title": "D",
         "type": "column",
         "color": "#000000",
         'fontSize': 16,
         'valueAxis': 'v1',
         "valueField": "D"
      },

      {
         "balloonText": "<b>[[title]]</b><br><span style='font-size:24px'>[[category]]: <b>[[value]]</b></span>",
         "fillAlphas": 0.5,
         "labelText": "[[value]]%",
         "lineAlpha": 0.3,
         'lineColor': '#f79646',
         "title": "年级 A",
         "type": "column",
         "color": "#000000",
         'fontSize': 16,
         'valueAxis': 'v2',
         "valueField": "A2",
         "visibleInLegend":false
      },
      {
         "balloonText": "<b>[[title]]</b><br><span style='font-size:24px'>[[category]]: <b>[[value]]</b></span>",
         "fillAlphas": 0.5,
         "labelText": "[[value]]%",
         "lineAlpha": 0.3,
         'lineColor': '#ffcc00',
         "title": "年级 B",
         "type": "column",
         "color": "#000000",
         'fontSize': 16,
         'valueAxis': 'v2',
         "valueField": "B2",
         "visibleInLegend":false
      },
      {
         "balloonText": "<b>[[title]]</b><br><span style='font-size:24px'>[[category]]: <b>[[value]]</b></span>",
         "fillAlphas": 0.5,
         "labelText": "[[value]]%",
         "lineAlpha": 0.3,
         'lineColor': '#4bacc6',
         "title": "年级 C",
         "type": "column",
         "color": "#000000",
         'fontSize': 16,
         'valueAxis': 'v2',
         "valueField": "C2",
         "visibleInLegend":false
      },
      {
         "balloonText": "<b>[[title]]</b><br><span style='font-size:24px'>[[category]]: <b>[[value]]</b></span>",
         "fillAlphas": 0.5,
         "labelText": "[[value]]%",
         "lineAlpha": 0.3,
         'lineColor': '#558ed5',
         "title": "年级 D",
         "type": "column",
         "color": "#000000",
         'fontSize': 16,
         'valueAxis': 'v2',
         "valueField": "D2",
         "visibleInLegend":false
      }
   ],
   "categoryField": "kemu",
   "categoryAxis": {
      "gridPosition": "start",
      "axisAlpha": 0,
      "gridAlpha": 0,
      "position": "left",
      'fontSize': 24,
   },
   "export": {
      "enabled": true
   }
}

2.横向柱状叠加图

核心代码:

//叠加柱状图
var amOptions = {
   "type": "serial",
   "theme": "light",
   "legend": {
      "horizontalGap": 10,
      "maxColumns": 1,
      "position": "right",
      "useGraphSettings": true,
      "markerSize": 10,
      'fontSize': 24,
   },
   "dataProvider": data,
   "valueAxes": [{
      "stackType": "100%",
      "axisAlpha": 0,
      "gridAlpha": 0.5,
      'autoGridCount': false,
      'gridCount': 0,
      'fontSize': 24,
   }],
   "graphs": [{
      "balloonText": "<b>[[title]]</b><br><span style='font-size:24px'>[[category]]: <b>[[value]]</b></span>",
      "fillAlphas": 0.8,
      "labelText": "[[value]]%",
      "lineAlpha": 0.3,
      "title": "A水平",
      "type": "column",
      "color": "#000000",
      "valueField": "A",
      "fillColorsField": "Acolor",
      'lineColor': '#548235',
      'fontSize': 16,
   }, {
      "balloonText": "<b>[[title]]</b><br><span style='font-size:24px'>[[category]]: <b>[[value]]</b></span>",
      "fillAlphas": 0.8,
      "labelText": "[[value]]%",
      "lineAlpha": 0.3,
      "title": "B水平",
      "type": "column",
      "color": "#000000",
      "valueField": "B",
      "fillColorsField": "Acolor",
      'lineColor': '#a9d18e',
      'fontSize': 16,
   }, {
      "balloonText": "<b>[[title]]</b><br><span style='font-size:24px'>[[category]]: <b>[[value]]</b></span>",
      "fillAlphas": 0.8,
      "labelText": "[[value]]%",
      "lineAlpha": 0.3,
      "title": "C水平",
      "type": "column",
      "color": "#000000",
      "valueField": "C",
      "fillColorsField": "Acolor",
      'lineColor': '#c5e0b4',
      'fontSize': 16,
   }, {
      "balloonText": "<b>[[title]]</b><br><span style='font-size:24px'>[[category]]: <b>[[value]]</b></span>",
      "fillAlphas": 0.8,
      "labelText": "[[value]]%",
      "lineAlpha": 0.3,
      "title": "D水平",
      "type": "column",
      "color": "#000000",
      "valueField": "D",
      "fillColorsField": "Acolor",
      'lineColor': '#e2f0d9',
      'fontSize': 16,
   }],
   "rotate": true,
   "categoryField": "classname",
   "categoryAxis": {
      "gridPosition": "start",
      "axisAlpha": 0,
      "gridAlpha": 0,
      "position": "left",
      'fontSize': 24,
   },
   "export": {
      "enabled": true
   }
}

3.一些重要的属性:

rotate:是否旋转(横向/竖向)

valueAxes:y轴的值

categoryAxis:x轴的值

"labelText": "[[value]]%",显示百分号

另外如果显示的字体大于一个柱子的宽度,就会消失,可以适当调小即可

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
xml <!-- [xml] (xml / csv) 数据类型xml/csv--> ; <!-- 如果使用csv作为数据的话,需要使用这个属性;表示文件数据分隔符,(平常以";"和","为主) [;] (string) csv file data separator (you need it only if you are using csv file for your data) --> 1 <!-- 如果使用的是csv数据,可以设置跳过几行再显示数据,默认为0表示csv中的数据全部显示,大于n(n>0);表示前面n行都不显示[0] (Number) if you are using csv data type, you can set the number of rows which should be skipped here --> <!-- 设置系统中的字体[Arial] (font name) use device fonts, such as Arial, Times New Roman, Tahoma, Verdana... --> <!-- 设置所有文本的大小,默认为11,具体的文本的字体大小也可以在下面的设置中设置[11] (Number) text size of all texts. Every text size can be set individually in the settings below --> <!-- 同上[#000000] (hex color code) main text color. Every text color can be set individually in the settings below--> . <!-- 小数分隔符,默认为[,]注:该属性只是用来显示,而在csv数据文件中,必须使用[.] (string) decimal separator. Note, that this is for displaying data only. Decimals in data xml file must be separated with a dot --> <!-- 千位分隔符,默认为空[ ] (string) thousand separator. use "none" if you don't want to separate --> 3 <!-- 如果百分数格式的数字,后面的小数位小于该属性的值,则在小数后面加0补充。如54.2%,该属性设置为3,那么显示的效果为54.200%。[] (Number) if your value has less digits after decimal then is set here, zeroes will be added --> <!--设置科学记数法的最小值 [0.000001] If absolute value of your number is equal or less then scientific_min, this number will be form
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值