Chart.js的简单实用

准备开始工作,学习了一下chart.js,还是比较容易上手的,下面给大家介绍一下。

曲线图作为案例:

实例化Chart对象:

<body>
    <!-- 为了创建图表,我们要实例化一个Chart对象 -->
    <canvas id="myChart" width="400" height="400"></canvas>
</body>

数据设置:

var data = {
            labels : ["一月","二月","三月","四月","五月","六月","七月"],
            datasets : [
                        {
                            /*
                             * R:红色值。正整数 | 百分数

                               G:绿色值。正整数 | 百分数
                                
                               B:蓝色值。正整数| 百分数
                                
                               A:透明度。取值0~1之间
                             * */
                            fillColor : "rgba(220,220,220,0.5)",//填充颜色
                            strokeColor : "rgba(220,220,220,1)",//边框颜色
                            pointColor : "rgba(220,220,220,1)",//点的颜色
                            pointStrokeColor : "#fff",//点的边框颜色
                            data : [65,59,90,81,56,55,40]//输入的数据
                        },
                        {
                            fillColor : "rgba(151,187,205,0.5)",
                            strokeColor : "rgba(151,187,205,1)",
                            pointColor : "rgba(151,187,205,1)",
                            pointStrokeColor : "#fff",
                            data : [28,48,40,19,96,27,100]
                        }
                        ]
    }

图标选项设置:

var options = {//这是默认的
        // 网格线是否在数据线的上面        
        scaleOverlay : false,
       
        // 是否用硬编码重写y轴网格线
        scaleOverride : false,
       
        // y轴刻度的个数
        scaleSteps : null,

        // y轴每个刻度的宽度
        scaleStepWidth : null,

        // y轴的起始值
        scaleStartValue : null,


        // x轴y轴的颜色
        scaleLineColor : "rgba(0,0,0,1)",
        

        // x轴y轴的线宽    
        scaleLineWidth : 1,


        // 是否显示y轴的标签
        scaleShowLabels : true,
        

        // 标签显示值
        scaleLabel : "<%=value%>",
        

        // 标签的字体
        scaleFontFamily : "'Arial'",
        

        // 标签字体的大小
        scaleFontSize : 12,
        

        // 标签字体的样式
        scaleFontStyle : "normal",
        

        // 标签字体的颜色
        scaleFontColor : "#666",    
       
        // 是否显示网格线
        scaleShowGridLines : true,
       
        // 网格线的颜色
        scaleGridLineColor : "rgba(0,0,0,.1)",
        

        // 网格线的线宽
        scaleGridLineWidth : 1,    
       
        // 是否是曲线
        bezierCurve : true,
       
        // 是否显示点
        pointDot : true,
       
        // 点的半径
        pointDotRadius : 3,

        // 点的线宽
        pointDotStrokeWidth : 1,
       
        datasetStroke : true,

        // 数据线的线宽
        datasetStrokeWidth : 3,
       
        // 数据线是否填充颜色
        datasetFill : true,
       
        // 是否有动画效果
        animation : true,

        // 动画的步数
        animationSteps : 60,
       
        // 动画的效果
        animationEasing : "easeOutQuart",

        // 动画完成后调用
        onAnimationComplete : null,

       //响应式布局(兼容多个终端)

       responsive: true,

   }

//2d画布

var ctx = document . getElementById ( 'myChart' ) . getContext ( '2d' ) ;
new Chart ( ctx ) . Line ( data,options);



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值