博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
openchart.js的使用
阅读量:6419 次
发布时间:2019-06-23

本文共 3407 字,大约阅读时间需要 11 分钟。

hot3.png

1、引入js

OpenCharts是一个js包,包含了一系列js.只需要引入openchartjs即可

<script type="text/javascript" src="../lib/OpenCharts/OpenCharts.js"></script>

2、html前端书写

前端需要写canvas嵌套在div中摆放位置即可。

<div style="left: 0px; top: 0px; position: absolute;">

        <canvas id="canvas1" height="300px" width="500px"></canvas>
    </div>
    <div style="left: 510px; top: 0px; position: absolute;">
        <canvas id="canvas2" height="300px" width="500px"></canvas>
    </div>
    <div style="left: 1020px; top: 0px; position: absolute;">
        <canvas id="canvas3" height="600px" width="500px"></canvas>
    </div>
    <div style="left:0px;top:330px;position: absolute;">
           <canvas id="canvas4" height="400px" width="500px"  ></canvas>
    </div>

3、js书写

饼状图在angluarjs中书写

$scope.pieItems = [];
    $scope.pieChart = {};
    $scope.pieInit = function(){
        $scope.pieItems.push(new OpenCharts.Item(10,"未知的性别","#838B8B"));
        $scope.pieItems.push(new OpenCharts.Item(206,"男","#0000CD"));
        $scope.pieItems.push(new OpenCharts.Item(100,"女","#F00"));
        $scope.pieItems.push(new OpenCharts.Item(35,"未说明的性别","#FCF6CF"));
        $scope.pieChart = new OpenCharts.Chart.PieChart("canvas1");
        $scope.pieChart.strTitle = "客户的性别分析饼状图";
        var message = "${itemName}${itemCaption}性人数为${itemData}人";
        $scope.pieChart.addItems($scope.pieItems,"客户的");
        $scope.pieChart.addEventListener("mousedown",message);
        $scope.pieChart.render();
    }

在jqueryjs中书写

function init()

        {
            var items = [],items1 = [],items2 = [],items3 = [];
            var style = new OpenCharts.Style();
            style.fillStyle = "#F00";

            items.push({strCaption : '上海',data : 38.0,itemStyle:'#C0FFFF'});

            items.push(new OpenCharts.Item(9.0,"云南",style));
            items.push(new OpenCharts.Item(9.0,"内蒙古","#FFC000"));
            items.push(new OpenCharts.Item(22,"北京","#FFFF00"));
            items.push(new OpenCharts.Item(6,"吉林","#92D050"));
            items.push(new OpenCharts.Item(20,"四川","#00B050"));
            items.push(new OpenCharts.Item(20,"天津","#00B0F0"));
            items.push(new OpenCharts.Item(0,"宁夏","#0070C0"));
            items.push(new OpenCharts.Item(6,"安徽","#002060"));
            items.push(new OpenCharts.Item(47,"山东","#7030A0"));
            items.push(new OpenCharts.Item(7,"山西","#C0504D"));
            items.push(new OpenCharts.Item(49,"广东","#9932CC"));
            items.push(new OpenCharts.Item(7,"广西","#FBF5E6"));
            items.push(new OpenCharts.Item(3,"新疆","#F6F9ED"));
            items.push(new OpenCharts.Item(27,"江苏","#EE1289"));
            items.push(new OpenCharts.Item(10,"黑龙江","#EEC900"));
            items.push(new OpenCharts.Item(0,"江西","#EBECE4"));
            items.push(new OpenCharts.Item(0,"河北","#ECF1EF"));
            items.push(new OpenCharts.Item(8,"河南","#FCF6CF"));
            items.push(new OpenCharts.Item(21,"浙江","#8B6914"));
            items.push(new OpenCharts.Item(0,"海南","#FEF6E4"));
            items.push(new OpenCharts.Item(8,"湖北","#FCF8DC"));
            items.push(new OpenCharts.Item(11,"湖南","#458B74"));
            items.push(new OpenCharts.Item(20,"福建","#838B8B"));
            items.push(new OpenCharts.Item(0,"西藏","#0000CD"));
            items.push(new OpenCharts.Item(3,"贵州","#0000CD"));
            items.push(new OpenCharts.Item(39,"辽宁","#FF4040"));
            items.push(new OpenCharts.Item(2,"重庆","#CD3333"));
            items.push(new OpenCharts.Item(4,"陕西","#8B2323"));
            items.push(new OpenCharts.Item(0,"青海","#7FFF00"));
            items.push(new OpenCharts.Item(0,"甘肃","#53868B"));

            charts = new OpenCharts.Chart.PieChart("canvas");

            charts.strTitle = "伦敦奥运会各省市参赛选手";

            var message = "${itemName}${itemCaption}省参赛选手人数为${itemData}人";

            charts.addItems(items,"伦敦奥运会");
            charts.addEventListener("mousedown",message);
            //charts.addEventListener("mousemove",message);

            charts.render();

        }

4、效果图为

160350_WObk_2404345.png

 

转载于:https://my.oschina.net/Seaside20151225/blog/813832

你可能感兴趣的文章
Vue 折腾记 - (8) 写一个挺靠谱的多地区选择组件
查看>>
VS Code折腾记 - (3) 多图解VSCode基础功能
查看>>
再不懂区块链,你就OUT了!
查看>>
教你玩转自定义View—手撸一个倒计时控件如此简单
查看>>
『翻译』Node.js 调试
查看>>
我的iOS开发之路总结(更新啦~)
查看>>
Java NIO之拥抱Path和Files
查看>>
微信原图泄露的只能是 Exif ,你的隐私不在这!!!
查看>>
微信小程序教学第三章(含视频):小程序中级实战教程:列表篇-页面逻辑处理...
查看>>
页面间通信与数据共享解决方案简析
查看>>
Swift 中 Substrings 与 String
查看>>
作为一个开源软件的作者是一种什么样的感受?
查看>>
移动端适配知识你到底知多少
查看>>
Java基础笔记16
查看>>
TiDB 在 G7 的实践和未来
查看>>
重新认识javascript对象(三)——原型及原型链
查看>>
小学生学“数学”
查看>>
【Vue】组件使用之参数校验
查看>>
FastDFS蛋疼的集群和负载均衡(十七)之解决LVS+Keepalived遇到的问题
查看>>
深入剖析Redis系列(二) - Redis哨兵模式与高可用集群
查看>>