• ExtJS-绘图(Drawing)


    更新记录
    2022年7月28日 发布。
    2022年7月26日 从笔记迁移到博客。

    ExtJS教程汇总:https://www.cnblogs.com/cqpanda/p/16328016.html


    PS:不推荐使用ExtJS的绘图功能,实在太丑了。推荐其他开源或者商业的绘图工具包。


    绘图(Drawing)

    说明

    使用ExtJS提供的绘图功能可以实现绘制图形
    实际上是在Canvas画布中生成图像

    安装方法1-直接引入CSS和JS文件

    此方法适合于直接引入CSS文件和JS文件的项目

    将SDK目录下的build目录复制到项目目录下

    image
    引入/build/packages/charts包的CSS文件和JS文件即可使用

    1. <link rel="stylesheet" href="/build/packages/charts/classic/neptune/resources/charts-all-debug.css">
    2. <script src="/build/packages/charts/classic/charts-debug.js">script>

    安装方法2-引入charts包

    此方法适合于使用Sencha CMD的项目

    打开项目文件夹下的app.json文件

    image

    引入charts包

    1. "requires": [
    2. "font-awesome",
    3. "charts"
    4. ],

    编译项目

    sencha app build

    实例

    绘制圆形(Circle Drawing)

    1. {
    2. xtype: 'draw',
    3. sprites: [{
    4. type: 'circle',
    5. fillStyle: 'red',
    6. r: 100,
    7. cx: 100,
    8. cy: 100
    9. }],
    10. height:205,
    11. width:205,
    12. }

    绘制矩形(Rectangle Drawing)

    1. {
    2. xtype: 'draw',
    3. sprites: [{
    4. type: 'rect',
    5. height : 200,
    6. width: 600,
    7. fill: 'red'
    8. }],
    9. height:150,
    10. width:300,
    11. }

    绘制扇形(Arc Drawing)

    1. {
    2. xtype: 'draw',
    3. width: 600,
    4. height: 400,
    5. sprites: [{
    6. type: 'arc',
    7. cx: 200,
    8. cy: 200,
    9. r: 100,
    10. fillStyle: '#1F6D91',
    11. startAngle: 0,
    12. endAngle: Math.PI,
    13. anticlockwise: true
    14. }]
    15. }

    绘制椭圆(Ellipse Drawing)

    1. {
    2. xtype: 'draw',
    3. renderTo: Ext.getBody(),
    4. width: 600,
    5. height: 200,
    6. sprites: [{
    7. type: 'ellipse',
    8. cx: 100,
    9. cy: 100,
    10. rx: 80,
    11. ry: 50,
    12. fillStyle: '#1F6D91'
    13. }]
    14. }

    绘制椭圆扇形(Elliptical Arc Drawing)

    1. {
    2. xtype: 'draw',
    3. renderTo: Ext.getBody(),
    4. width: 600,
    5. height: 200,
    6. sprites: [{
    7. type: 'ellipticalArc',
    8. cx: 100,
    9. cy: 100,
    10. rx: 80,
    11. ry: 50,
    12. fillStyle: '#1F6D91',
    13. startAngle: 0,
    14. endAngle: Math.PI,
    15. anticlockwise: true
    16. }]
    17. }

    绘制图片(Image Drawing)

    1. {
    2. xtype: 'draw',
    3. renderTo: Ext.getBody(),
    4. width: 600,
    5. height: 200,
    6. sprites: [{
    7. type: 'image',
    8. src : '/resources/images/2021-01-20_111540.jpg'
    9. }]
    10. }

    绘制正方形(Square Drawing)

    1. {
    2. xtype: 'draw',
    3. width: 300,
    4. height: 300,
    5. sprites: [{
    6. type: 'square',
    7. height: 200,
    8. width: 250,
    9. fill: 'green'
    10. }]
    11. }

    旋转图形(Rotate Drawing)

    1. {
    2. xtype: 'draw',
    3. width: 200,
    4. height: 200,
    5. sprites: [{
    6. type: 'rect',
    7. height: 100,
    8. width: 100,
    9. x:50,
    10. y:50,
    11. fill: 'red',
    12. rotate: {
    13. degrees: 45
    14. }
    15. }],
    16. }

    指定起始绘制位置(Translate Drawing)

    1. {
    2. xtype: 'draw',
    3. width: 400,
    4. height: 400,
    5. sprites: [{
    6. type: 'rect',
    7. height : 200,
    8. width: 200,
    9. fill: 'red',
    10. translate: {
    11. x:10,
    12. y:10
    13. }
    14. }],
    15. }

    绘制文本(Text Drawing)

    1. {
    2. xtype: 'draw',
    3. width: 600,
    4. height: 200,
    5. sprites: [{
    6. type: 'text',
    7. x: 200,
    8. y: 100,
    9. text: 'panda666.com',
    10. fontSize: 30,
    11. fillStyle: 'red'
    12. }]
    13. }

    绘制自定义点图

    1. {
    2. xtype: 'draw',
    3. width: 300,
    4. height:200,
    5. sprites: [{
    6. type: 'path',
    7. path: 'M150 0 L25 100 L250 100 Z',
    8. strokeStyle: '#333',
    9. fill: 'green',
    10. lineWidth: 2
    11. }]
    12. }
  • 相关阅读:
    【华为OD机试真题 python】 报数游戏【2022 Q4 | 100分】
    matlab函数 状态空间系统ss、能控性矩阵ctrb、矩阵的秩rank、能控标准型canon、零极点配置place、系统极点pole等函数(线性定常系统)
    vision transformer的计算复杂度
    apache开启https
    集合java
    threehit二次注入案例
    改进的萤火虫优化算法(Matlab代码实现)
    初学Bootstrap
    【三维重建】【SLAM】SplaTAM:基于3D高斯的密集RGB-D SLAM
    react高频面试题总结(附答案)
  • 原文地址:https://blog.csdn.net/weixin_38304160/article/details/126028451