amCharts之柱形图

先从官网给的demo开始看,最简单的demo: columnSimple 图如下:


代码如下:

[html]  view plain copy print ?
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">  
  2. <html>  
  3.       
  4.     <head>  
  5.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  6.         <title>amCharts examples</title>  
  7.         <link rel="stylesheet" href="style.css" type="text/css">  
  8.         <script src="../amcharts/amcharts.js" type="text/javascript"></script>           
  9.         <script type="text/javascript">  
  10.             var chart;  
  11.             var chartData = [{  
  12.                 country: "USA",  
  13.                 visits: 4025  
  14.             }, {  
  15.                 country: "China",  
  16.                 visits: 1882  
  17.             }, {  
  18.                 country: "Japan",  
  19.                 visits: 1809  
  20.             }, {  
  21.                 country: "Germany",  
  22.                 visits: 1322  
  23.             }, {  
  24.                 country: "UK",  
  25.                 visits: 1122  
  26.             }, {  
  27.                 country: "France",  
  28.                 visits: 1114  
  29.             }, {  
  30.                 country: "India",  
  31.                 visits: 984  
  32.             }, {  
  33.                 country: "Spain",  
  34.                 visits: 711  
  35.             }, {  
  36.                 country: "Netherlands",  
  37.                 visits: 665  
  38.             }, {  
  39.                 country: "Russia",  
  40.                 visits: 580  
  41.             }, {  
  42.                 country: "South Korea",  
  43.                 visits: 443  
  44.             }, {  
  45.                 country: "Canada",  
  46.                 visits: 441  
  47.             }, {  
  48.                 country: "Brazil",  
  49.                 visits: 395  
  50.             }, {  
  51.                 country: "Italy",  
  52.                 visits: 386  
  53.             }, {  
  54.                 country: "Australia",  
  55.                 visits: 384  
  56.             }, {  
  57.                 country: "Taiwan",  
  58.                 visits: 338  
  59.             }, {  
  60.                 country: "Poland",  
  61.                 visits: 328  
  62.             }];  
  63.   
  64.   
  65.             AmCharts.ready(function () {  
  66.                 chart = new AmCharts.AmSerialChart();//创建一个AmSerialChart对象  
  67.                 chart.dataProvider = chartData;//dataProvider 数据提供的对象 对应上面的json数据  
  68.                 chart.categoryField = "country";//X轴上的值  
  69.                 chart.startDuration = 1;  
  70.   
  71.  <span style="white-space:pre">     </span>//X轴  
  72.                 var categoryAxis = chart.categoryAxis;  
  73.                 //categoryAxis.labelRotation =45 ;//X轴下面值的角度  
[html]  view plain copy print ?
  1. <span style="white-space:pre">      </span>//Y轴  
  2.                 var graph = new AmCharts.AmGraph();  
  3.                 graph.valueField = "visits";//柱形图显示的值  
  4.                 graph.balloonText = "[[category]]: [[value]]";//鼠标放上所显示的  
  5.                 graph.type = "column";//Y轴的类型 有line、column、step、smoothedLine、candlestick、ohlc  
  6.                 graph.lineAlpha = 0;//border透明度  
  7.                 graph.fillAlphas = 0.8;//柱子的透明度  
  8.                 chart.addGraph(graph);  
  9.                 chart.write("chartdiv");  
  10.             });  
  11.         </script>  
  12.     </head>  
  13.       
  14.     <body>  
  15.         <div id="chartdiv" style="width: 100%; height: 400px;"></div>  
  16.     </body>  
  17. </html>  

AmSerialChart 是画地域图、柱形图 等等的 对象。

AmGraph 是画Y轴的对象。

如果你想不同的柱子加 不同的颜色的话 需要做2件事:

1.把json数据多加一个属性 ex:{country:"USA",visits:4025,color: "#F8FF01"}

2.在Y轴的对象上添加一个颜色属性  graph.colorField = "color";

这样就可以得到不同颜色。

第2个demo是双柱形图,如图:



  1. var chart;  
  2.   
  3.             var chartData = [{  
  4.                 dealer: "一月",  
  5.                 a: 2.6,  
  6.                 b: 2.7,  
  7.                  
  8.             }, {  
  9.                 dealer: "二月",  
  10.                 a: 2.6,  
  11.                 b: 2.7,  
  12.                  
  13.                 
  14.             }, {  
  15.                 dealer: "三月",  
  16.                 a: 2.6,  
  17.                 b: 2.7,  
  18.                   
  19.                 
  20.             }, {  
  21.                 dealer: "四月",  
  22.                 a: 2.6,  
  23.                 b: 2.7,  
  24.                   
  25.                 
  26.             }];  
  27.   
  28.             AmCharts.ready(function () {  
  29.                 // SERIALL CHART  
  30.                 chart = new AmCharts.AmSerialChart();  
  31.                 chart.dataProvider = chartData;  
  32.                 chart.categoryField = "dealer";  
  33.                 //chart.rotate = true;//把柱形图变成横向  
  34.   
  35.                 var categoryAxis = chart.categoryAxis;  
  36.                 categoryAxis.gridAlpha = 0.1;//数格的边线透明度  
  37.                 categoryAxis.axisAlpha = 0.4;//X轴的透明度  
  38.                 categoryAxis.inside=false;//X轴数值在图里面还是瓦面  
  39.                 categoryAxis.position = "bottom";//X轴位置  
  40.                       
  41.                 var valueAxis = new AmCharts.ValueAxis();  
  42.                 //valueAxis.stackType = "regular";  
  43.                 valueAxis.gridAlpha = 0;  
  44.                 valueAxis.axisAlpha = 0.4;  
  45.                 chart.addValueAxis(valueAxis);  
  46.   
  47.                 // firstgraph   
  48.                 var graph = new AmCharts.AmGraph();  
  49.                 graph.title = "注册用户";  
  50.                 //graph.labelText = "[[value]]";  
  51.                 graph.valueField = "a";//跟json数据中a相对应  
  52.                 graph.balloonText="[[title]]:[[value]]人" //鼠标放上显示的值  
  53.                 graph.type = "column";  
  54.                 graph.lineAlpha = 1;  
  55.                 graph.fillAlphas = 1;  
  56.                 graph.lineColor = "#83c417";  
  57.                 chart.addGraph(graph);  
  58.   
  59.                 // second graph                                
  60.                 graph = new AmCharts.AmGraph();  
  61.                 graph.title = "停用用户";  
  62.                 //graph.labelText = "[[value]]";  
  63.                 graph.valueField = "b";  
  64.                 graph.balloonText="[[title]]:[[value]]人"  
  65.                 graph.type = "column";  
  66.                 graph.lineAlpha = 1;  
  67.                 graph.fillAlphas = 1;  
  68.                 //graph.fillColors="#ffc92e"  
  69.                 graph.lineColor = "#f27324";  
  70.                 chart.addGraph(graph);  
  1.   
  1. <span style="white-space:pre">      </span>//控制柱子上鼠标事件的代码,修改tip的样式  
  2.         var balloon = chart.balloon;  
  3.         balloon.adjustBorderColor = true;  
  4.         balloon.horizontalPadding = 10;  
  5.         balloon.fontSize = 14;  
  6.         balloon.pointerWidth= 5;  
  7.         balloon.color = "#000000";  
  8.         balloon.cornerRadius = 0;  
  9.         balloon.borderThickness=1;  
  10.         balloon.borderColor="#999999";  
  11.         balloon.borderAlpha=1;  
  12.         balloon.fillColor = "#FFFFFF";  
  13.                
  14.   
  15.                 // LEGEND 用来显示下面分组的代码  
  16.                 var legend = new AmCharts.AmLegend();  
  17.                 legend.position = "bottom";  
  18.                 legend.borderAlpha = 0;  
  19.                 legend.horizontalGap = 10;  
  20.                 legend.switchType = "v";//图片上面默认显示对号   
  21.                 chart.addLegend(legend);  
  22.   
  23.                 // WRITE  
  24.                 chart.write("chartdiv");  
  25.             });  
 amCharts.AmLegend() 对象 用来生成分组。
如果想变成一个柱子代表几个数据的话,如下图:


只需要增加valueAxis.stackType = "regular"; 代码就可以了


=========================

 关于amcahrt的破解和使用

=============================================================


现在做图表的chart使用,amchart很方便,很漂亮,
新建一个类,比如amDemoChart.as如下,接着,在自己的组建中,引用即可,拓展后,可以和java类连接,用来展示想要的数据图表
但是,注意,展示中,可能很多效果不如意,所以一定要先明白那些属性的意义,这个amchart的网站是有的,这里给个注意点,amchart人如果横轴坐标不显示,注意看labelrotaion 的设置
package
{
import com.amcharts.AmSerialChart;
public class AmcChart extends AmSerialChart 

  override protected function createChildren():void{ 
   super.createChildren(); 
   if(_amchartsLink){ 
    _amchartsLink.alpha=0; 
    _amchartsLink.width=0; 
    _amchartsLink.height=0; 
    _amchartsLink.visible=false;
   } 
   return; 
  } 
  
}
}
如上可以破解,去除amchart上的那个小链接


如下是一个例子

var amnew:amDemoChart=new amDemoChart();
amnew.dataProvider=array;
    
    amnew.percentHeight=100;
    amnew.percentWidth=100;
    amnew.styleName="amStyle";
    amnew.setStyle("marginTop",30);
    amnew.setStyle("marginLeft",60);  
    amnew.setStyle("marginBottom",60); 
    amnew.categoryField="NAME";
    amnew.setStyle("startDuration",1);
    amnew.setStyle("angle",30);
    amnew.setStyle("depth3D",15);
    amnew.setStyle("plotAreaFillAlphas",[0]);
    amnew.autoMargins=false;
    
    ag1.balloonText="[[category]]时间:[[value]]" ;//注意此处的两个值,是默认的变量,不能修改
    ag1.setStyle("color","0x6600CC");
    ag1.title=FieldYTitle;
    ag1.valueField="VALUE"; 
    ag1.type = "column";
    ag1.setStyle("lineAlpha",0);
    ag1.setStyle("fillColors",[0xADD981,0xADD981]);
    ag1.setStyle("fillAlphas",[0.8]);
    
    amnew.graphs.push(ag1);
    
    ag2.markerType="line";
    ag2.setStyle("bullet","round");
    ag2.setStyle("lineThickness","2");
    ag2.title=FieldYTitle;
    ag2.valueField="VALUE";
    amnew.graphs.push(ag2); 
        
    var cAxis:CategoryAxis=new CategoryAxis();
    cAxis.gridPosition="start";
    cAxis.setStyle("gridCount",ChartDataXMLList.length());
    cAxis.setStyle("dashLength",5);
    //cAxis.setStyle("labelRotation","60");
    cAxis.setStyle("fontSize","11");
    
    var vAxis:ValueAxis=new ValueAxis();
    vAxis.setStyle("dashLength",5);
    
    amnew.categoryAxis=cAxis;
    amnew.valueAxes.push(vAxis);
    
    var amLd:AmLegend=new AmLegend();
    amLd.dataProvider=amnew;
    amLd.percentWidth=100;
    amLd.setStyle("switchType","v");
    amLd.setStyle("marginLeft",200);
    amLd.setStyle("marginTop",4);
    amLd.textClickEnabled=false;
    
    var amBalloon:AmBalloon=new AmBalloon();
    amBalloon.setStyle("cornerRadius",10);
    amBalloon.setStyle("borderThickness",2);
    amBalloon.setStyle("borderColor","#FFFFFF");
    amBalloon.setStyle("borderAlpha",1);
    amnew.balloon=amBalloon;
    
    var amChartCursor:ChartCursor=new ChartCursor();
    amChartCursor.zoomable=false;
    amChartCursor.categoryBalloonEnabled=false;
    amChartCursor.setStyle("cursorAlpha","0");
    amnew.chartCursor=amChartCursor;
     
    this.addChild(amLd);
    this.addChild(amnew);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值