美文网首页
Chartjs 画个饼图

Chartjs 画个饼图

作者: 十九贝勒 | 来源:发表于2018-06-01 17:56 被阅读180次

下载地址

chartjs

界面引用

<script type="text/javascript" src="Chart.min.js"></script>

sql语句

select platform_name,count(id) from platform_user
group by platform_name;

组装饼图数据

List nameList = result.stream()
        .map(Pie::getName)
        .collect(Collectors.toList()), countList = result.stream()
        .map(Pie::getCount)
        .collect(Collectors.toList());
    Object[] arrayResult=new Object[]{nameList,countList};

界面设置

<canvas id="chart-hy"></canvas>

JS代码画饼图

function initPie(names,datas,id,typeName,title){
   var randomScalingFactor = function() {
            return Math.round(Math.random() * 100);
        };

        var config = {
            type: 'pie',
            data: {
                datasets: [{
                    data: datas,
                    backgroundColor: [
                        window.chartColors.red,
                        window.chartColors.blue
                    ],
                    label: typeName
                }
                ],
                labels: names
            },
        options: {
                responsive: true,
                legend: {
                    position: 'top',
                },
                title: {
                    display: true,
                    text: title
                },
                animation: {
                    animateScale: true,
                    animateRotate: true
                }
            }


        };

            var ctx = document.getElementById(id).getContext('2d');
            window.myPie = new Chart(ctx, config);

}

7、效果图


TIM图片20180601172838.png

相关文章

  • Chartjs 画个饼图

    下载地址 chartjs 界面引用 sql语句 组装饼图数据 界面设置 JS代码画饼图 7、效果图

  • 数据可视化

    参考资料 chartjs官网 搜狗浏览器不能正常显示? chartjs中文网 chartjs highcharts...

  • Matplotlib实践使用笔记——基本画图

    基本画图操作 内容包括画线、条形图、直方图、饼图。 画线 画条形图 简单条形图 直方图 统计出现的次数 饼状图 会...

  • matplotlib绘制图表

    python中使用matplotlib库可以快速画简单的图表下面介绍下柱状图和饼图绘制1 柱状图绘制 2 饼状图绘...

  • R语言:pie3D绘制三维饼图

    导读: 前面画过二维饼图:R语言:pie绘制饼图[https://www.jianshu.com/p/60ffc3...

  • vue-chartjs文档翻译

    原文地址: https://vue-chartjs.org/zh-cn/guide/ 起步 vue-chartjs...

  • iOS 画个简单的饼图

    闲来无事,把之前仿照网友敲的饼图代码传上来,供以后查看,先看看效果图: 先创建一个CAShapeLayer子类,这...

  • canvas画饼图(四) 饼图动画

    饼图的动画饼图的动画主要有两个:一个是刚开始的饼图由小到大,鼠标到饼图上面饼图,饼图变大或者变小 实现思路饼图变大...

  • vue+elementUi+echarts 折线图组件

    echarts官网 效果 ? 此图并非折线图饼图联动 折线图饼图联动组件飞机票 ?饼图点击事件再饼图组件中 饼图组...

  • echart 画图技巧汇总

    1.饼图中间画文字 2.柱状图圆角和lable自定义

网友评论

      本文标题:Chartjs 画个饼图

      本文链接:https://www.haomeiwen.com/subject/xupksftx.html