echart的使用记录

引入了dist文件夹

还有echarts.js文件

<!DOCTYPE html>

<head>
    <meta charset="utf-8">
    <title>ECharts</title>
</head>
<body>
    <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
    <div id="main" style="height:400px;width: 500px;"></div>
    <!-- ECharts单文件引入 -->
   <script src="js/echarts.js"></script>
     <script type="text/javascript">
       require.config({
           paths: {
               echarts: 'dist'
           }
       });
       require(
           [
               'echarts',
               'echarts/chart/pie',// 这个是圆饼图
           ],
           function (ec) {
               var myChart = ec.init(document.getElementById('main'));
               var option = {
               color:['rgba(254,0,0,0.5)','rgba(0,255,255,0.5)'],//颜色更改
                     title : {
      /* text: '某站点用户访问来源',  大标题
//        subtext: '纯属虚构子标题',*/
       x:'center'
   },
   tooltip : {
       trigger: 'item',
       formatter: "{a} <br/>{b} : {c} ({d}%)",
       show:false
   },
   legend: {
       orient : 'vertical',
       show:false,//左上方的图标是否显示
       x : 'left',
       data:['上架商标','下架商标']
   },
   toolbox: {//右上角的工具
       show : false,
       feature : {
           mark : {show: true},
           dataView : {show: true, readOnly: false},
           magicType : {
               show: true, 
               type: ['pie', 'funnel'],
               option: {
                   funnel: {
                       x: '25%',
                       width: '50%',
                       funnelAlign: 'left',
                       max: 1548
                   }
               }
           },
           restore : {show: true},
           saveAsImage : {show: true}
       }
   },
    calculable : true,//最外围的圈
   
   series : [
       {
           name:'访问来源',
           type:'pie',
           radius : '55%',
           center: ['50%', '60%'],
           data:[
               {value:335, name:'上架商标78'},
               {value:310, name:'下架商标80'}
           ]
       }
   ]
                }
                myChart.setOption(option);
            }
        );
    </script>

</body>


效果图



<!DOCTYPE html>
<head>
<meta charset="utf-8">
 <title>ECharts - 折线图</title>
</head>
<body>
    <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
    <div id="main" style="height: 400px; width: 600px"></div>
    <!-- ECharts单文件引入 -->
    <script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
    <script type="text/javascript">
        // 路径配置
        require.config({
            paths : {
                echarts : 'http://echarts.baidu.com/build/dist'
            }
        });
        // 使用
        require([ 'echarts', 'echarts/chart/line' // 使用折线图就加载line模块,按需加载
        ], function(ec) {
            // 基于准备好的dom,初始化echarts图表
            var myChart = ec.init(document.getElementById('main'));
            var option = {
//           color:['rgba(254,0,0,0.5)'],
                title : {
                    text : '未来一周气温变化',
                    subtext : '纯属虚构'
                },
                //数据提示框配置
                tooltip : {
                    trigger: "item"//可选item和axis  axis会有线的~~默认蓝色详细看文档更改
                },
                     //图例配置
                legend : {
                 show:false,
                    data : [ '最高气温', '最低气温' ]
                },
                //工具箱配置
                toolbox : {
                    show : false,
                    feature : {
                        mark : {
                            show : true
                        },
                        dataView : {
                            show : true,
                            readOnly : false
                        },
                        magicType : {
                            show : true,
                            type : [ 'line', 'bar' ]
                        },
                        restore : {
                            show : true
                        },
                        saveAsImage : {
                            show : true
                        }
                    }
                },
     
             calculable : true,
                xAxis : [ {
                axisLine:{lineStyle:{color: 'rgba(254,0,0,0.5)',width: '2',type: 'solid'}},
                    type : 'category',
                    boundaryGap : false,


                    data : [ '周一', '周二', '周三', '周四', '周五', '周六', '周日' ]
                } ],
                yAxis : [ {
                axisLine:{lineStyle:{color: 'rgba(254,0,0,0.5)',width: '2',type: 'solid'}},
                    type : 'value',
                    axisLabel : {
                        formatter : '{value} °C'
                    }
                } ],


                //图表Series数据序列配置
                series : [ {
                    type : 'line',
itemStyle : {  
                   normal : {   color : '#f00',  lineStyle : {  width : 2  },   label : {   show : true,   position : 'top',   textStyle : {   fontStyle : 'bolder',     fontSize : 15  }  }   }  
               },  
                    data : [ 11, 11, 15, 13, 12, 13, 10 ],
                     symbol : 'emptyCircle'
                    
//                  markPoint : {
//                      data : [ {name: '标注1', value: 100, xAxis: 0, yAxis: 11},{name: '标注1', value: 100, xAxis: 1, yAxis: 11}, {name: '标注1', value: 100, xAxis: 2, yAxis: 20}, {name: '标注1', value: 100, xAxis: 3, yAxis: 20}, {name: '标注1', value: 100, xAxis: 4, yAxis: 20}, {name: '标注1', value: 100, xAxis: 5, yAxis: 20}, {name: '标注1', value: 100, xAxis: 6, yAxis: 20}],
//                 itemStyle:{normal:{color:'yellow'}}
//                  }
//                  markLine : {
//                      data : [ {
//                          type : 'average',
//                          name : '平均值'
//                      } ]}
                    }

                    ]
                
            };
            // 为echarts对象加载数据 
            myChart.setOption(option);
        });
    </script>
</body>


猜你喜欢

转载自blog.csdn.net/qq_23114525/article/details/51280218
今日推荐