d3.js的demo

本文通过实例介绍如何使用d3.js库创建数据驱动的可视化图表。从数据加载到绘制各种图表,包括折线图、柱状图和散点图,详细解析d3.js的API用法,帮助理解数据绑定和转换过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html>
<html style="overflow: hidden;">
<head>
    <meta charset="UTF-8">
    <title>流程设计工具</title>
    <link href="https://cdn.bootcss.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="https://cdn.bootcss.com/jqueryui/1.12.1/jquery-ui.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
    <script src="https://cdn.bootcss.com/jqueryui/1.12.1/jquery-ui.min.js"></script>
    <script src="https://cdn.bootcss.com/d3/4.11.0/d3.min.js"></script>
    <script src="https://cdn.bootcss.com/d3-transform/1.0.4/d3-transform.min.js"></script>
    <style type="text/css">
        .left-wrapper {
            width: 250px;
            position: absolute;
            top:0px;
            bottom: 0px;
            left: 0px;
            background: #f0f0f0;
            border-right: solid 1px #e7e7e7;
        }
        .middle-wrapper {
            position: absolute;
            top: 0px;
            bottom: 0px;
            left: 250px;
            right: 250px;
        }
        .right-wrapper {
            position: absolute;
            width: 250px;
            top: 0px;
            bottom: 0px;
            right: 0px;
            background: #f5f5f5;
            border-left: solid 1px #e7e7e7;
        }

        .sidebar-nav,
        .sidebar-nav ul {
            list-style: none;
            padding: 0px;
        }

        .sidebar-nav > li:nth-child(odd),
        .sidebar-nav ul li:nth-child(odd) {
            background: #f0f0f0;
        }
        .sidebar-nav > li:nth-child(even),
        .sidebar-nav ul > li:nth-child(even) {
            background: #fff;
        }

        .sidebar-nav li {
            text-indent: 4px;
            line-height: 30px;
        }

        .sidebar-nav li li {
            text-indent: 15px;
        }

        .sidebar-nav li li li {
            text-indent: 25px;
        }

        .sidebar-nav li a {
            display: block;
            text-decoration: none;
            color: #333;
        }

        .sidebar-nav li.active a {
            background-color: #3e99ff;
        }

        .sidebar-nav li a>i+span {
            margin-left: 3px;
        }

        .sidebar-nav li a:hover {
            text-decoration: none;
            background: rgba(255, 255, 255, 0.2);
        }

        .sidebar-nav li a:active, .sidebar-nav li a:focus {
            text-decoration: none;
        }

        .middle-wrapper h4,
        .right-wrapper h4 {
            font-size: 1em;
            height: 40px;
            border-bottom: solid 1px #e7e7e7;
            text-align: center;
            line-height: 40px
        }

        .bpmn .node rect {
            width:180px;
            height:36px;
            cursor: pointer;
            stroke: #333;
            stroke-width:2;
            fill: #fff;
        }

        .bpmn .node.active rect,
        .bpmn .node.active circle {
            stroke: lightblue;
        }

        .bpmn .node circle {
            stroke: #333;
            stroke-width: 2px;
            fill: #fff;
            cursor: crosshair;
        }

        .bpmn .node circle.end {
            fill: orange;
        }

        .bpmn .cable {
            stroke: #333;
            stroke-width: 2px;
            fill: none;
        }
    </style>
</head>

<body>
<div class="container-fuild">
    <div id="left-wrapper" class="left-wrapper">
        <ul class="sidebar-nav">
            <li>
                <a class="open">
                    <i class="fa fa-folder-o"></i>
                    <span>源/目标</span>
                </a>
                <ul>
                    <li class="node" data-id="101">
                        <a href="">
                            <i class="fa fa-database"></i>
                            <span>读数据</span>
                        </a>
                    </li>
                    <li class="node" data-id="102">
                        <a href="">
                            <i class="fa fa-database"></i>
                            <span>写数据</span>
                        </a>
                    </li>
                </ul>
            </li>
            <li>
                <a>
                    <i class="fa fa-folder-o"></i>
                    <span>数据预处理</span>
                </a>
                <ul>
                    <li class="node" data-id="211">
                        <a href="">
                            <i class="fa fa-crosshairs" aria-hidden="true"></i>
                            <span>类型转换</span>
                        </a>
                    </li>
                    <li class="node" data-id="212">
                        <a href="">
                            <i class="fa fa-crosshairs" aria-hidden="true"></i>
                            <span>拆分</span>
                        </a>
                    </li>
                    <li class="node" data-id="213">
                        <a href="">
                            <i class="fa fa-crosshairs" aria-hidden="true"></i>
                            <span>缺失值填充</span>
                        </a>
                    </li>
                    <li class="node" data-id="214">
                        <a href="">
                            <i class="fa fa-crosshairs" aria-hidden="true"></i>
                            <span>归一化</span>
                        </a>
                    </li>
                    <li class="node" data-id="215">
                        <a href="">
                            <i class="fa fa-crosshairs" aria-hidden="true"></i>
                            <span>标准化</span>
                        </a>
                    </li>
                </ul>
            </li>
            <li>
                <a>
                    <i class="fa fa-folder-o"></i>
                    <span>特征工程</span>
                </a>
            </li>
            <li>
                <a>
                    <i class="fa fa-folder-o"></i>
                    <span>机器学习</span>
                </a>
                <ul>
                    <li>
                        <a>
                            <i class="fa fa-folder-o"></i>
                            <span>二分类</span>
                        </a>
                        <ul>
                            <li class="node">
                                <a href="">
                                    <i class="fa fa-circle-o"></i>
                                    <span>GBDT二分类</span>
                                </a>
                            </li>
                            <li class="node">
                                <a href="">
                                    <i class="fa fa-circle-o"></i>
                                    <span>PS-SMART</span>
                                </a>
                            </li>
                            <li class="node">
                                <a href="">
                                    <i class="fa fa-circle-o"></i>
                                    <span>线性支持向量机</span>
                                </a>
                            </li>
                            <li class="node">
                                <a href="">
                                    <i class="fa fa-circle-o"></i>
                                    <span>逻辑回归二分类</span>
                                </a>
                            </li>
                        </ul>
                    </li>
                    <li>
                        <a>
                            <i class="fa fa-folder-o"></i>
                            <span>聚类</span>
                        </a>
                        <ul>
                            <li class="node">
                                <a href="">
                                    <i class="fa fa-circle-o"></i>
                                    <span>K均值聚类</span>
                                </a>
                            </li>
                        </ul>
                    </li>
                    <li>
                        <a>
                            <i class="fa fa-folder-o"></i>
                            <span>回归</span>
                        </a>
                        <ul>
                            <li class="node">
                                <a href="">
                                    <i class="fa fa-circle-o"></i>
                                    <span>GBDT回归</span>
                                </a>
                            </li>
                            <li class="node">
                                <a href="">
                                    <i class="fa fa-circle-o"></i>
                                    <span>线性回归</span>
                                </a>
                            </li>
                            <li class="node">
                                <a href="">
                                    <i class="fa fa-circle-o"></i>
                                    <span>PS_SMART回归</span>
                                </a>
                            </li>
                            <li class="node">
                                <a href="">
                                    <i class="fa fa-circle-o"></i>
                                    <span>PS线性回归</span>
                                </a>
                            </li>
                        </ul>
                    </li>
                </ul>
            </li>
        </ul>
    </div>
    <div class="middle-wrapper">
        <h4>实验名称</h4>
        <div id="idsw-bpmn" class="bpmn" style="position: relative; width: 100%; height: 100%;">
            <svg width="100%" height="100%">
                <defs>
                    <marker id="arrowhead" viewBox="0 0 10 10" refX="10" refY="5" markerWidth="4" markerHeight="4"
                            orient="auto">
                        <path d="M 0 0 L 10 5 L 0 10 z" stroke-width="0" stroke="#333"></path>
                    </marker>
                </defs>
            </svg>
        </div>
        <div
            style="height: 40px; border-top: solid 1px #e7e7e7; text-align: center; line-height: 40px; position: absolute;bottom: 2px; width: 100%">
            <a class="btn btn-link" href="#"><i class="fa fa-play-circle-o" aria-hidden="true"></i>&nbsp;运行</a>
            <a class="btn btn-link" href="#"><i class="fa fa-cloud-upload" aria-hidden="true"></i>&nbsp;部署</a>
            <a class="btn btn-link" href="#"><i class="fa fa-share-alt" aria-hidden="true"></i>&nbsp;分享</a>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    var workflow = {
        nodes: {}
    };
    $(function() {
        var svg = d3.select("svg");
        // 绑定拖拽
        $('#left-wrapper .node').draggable({
            helper: "clone",
            addClass: false,
            connectToSortable: "#idsw-bpmn",
            start: function (e, ui) {
                ui.helper.addClass("ui-draggable-helper");
            },
            stop: function (e, ui) {

                var node = {
                    id: new Date().getTime(),
                    dataId: ui.helper.attr('data-id'),
                    x: ui.position.left - 250,
                    y: ui.position.top - 40,
                    text: ui.helper.text(),
                    inputs: 1,
                    outputs: 2
                };

                if(node.dataId == 101) {
                    node.inputs = 0;
                    node.outputs = 1;
                } else if(node.dataId == 102) {
                    node.inputs = 1;
                    node.outputs = 0;
                } else {
                    node.inputs = 1;
                    node.outputs = 1;
                }
                // 计算节点编号
                // if(workflow.nodes[node.dataId]) {
                //     workflow.nodes[node.dataId] += 1;
                // } else {
                //     workflow.nodes[node.dataId] = 1;
                // }
                var g = addNode(svg, node);

                g.call(
                    d3.drag()
                        .on("start", dragstarted)
                        .on("drag", dragged)
                        .on("end", dragended)
                );

                g.selectAll("circle.output").call(
                    d3.drag()
                        .on("start", linestarted)
                        .on("drag", linedragged)
                        .on("end", lineended)
                );

                g.selectAll("circle.input")
                    .on("mouseover", function() {
                        console.log("drawLine: " + drawLine)
                        if(drawLine) {
                            console.log("增加end....................")
                            d3.selectAll("circle.end").classed("end", false);
                            d3.select(this).classed("end", true);
                        }
                    });
            }
        });
    });

    var activeLine = null;
    var points = [];
    var translate = null;
    var drawLine = false;
    function linestarted() {
        console.log("start.............")
        drawLine = false;
        // 当前选中的circle
        var anchor = d3.select(this);
        console.log(anchor)
        // 当前选中的节点
        var node = d3.select(this.parentNode);

        var rect = node.node().getBoundingClientRect();
        var dx = rect.width / (+anchor.attr("output") + 1);
        var dy = rect.height;

        var transform = node.attr("transform");
        translate = getTranslate(transform);
        points.push([dx + translate[0], dy + translate[1]]);
        activeLine = d3.select("svg")
            .append("path")
            .attr("class", "cable")
            .attr("from", node.attr("id"))
            .attr("start", dx + ", " + dy)
            .attr("output", d3.select(this).attr("output"))
            .attr("marker-end", "url(#arrowhead)");
    }

    function linedragged() {
        console.log("drag.............")
        drawLine = true;
        points[1] = [d3.event.x + translate[0], d3.event.y + translate[1]];

        activeLine.attr("d", function() {
            return "M" + points[0][0] + "," + points[0][1]
                + "C" + points[0][0] + "," + (points[0][1] + points[1][1]) / 2
                + " " + points[1][0] + "," +  (points[0][1] + points[1][1]) / 2
                + " " + points[1][0] + "," + points[1][1];
        });
    }

    function lineended(d) {
        console.log("end.............")
        drawLine = false;
        var anchor = d3.selectAll("circle.end");
        console.log(anchor)
        console.log(anchor.size())
        if(anchor.empty()) {
            activeLine.remove();
        } else {
            var pNode = d3.select(anchor.node().parentNode);
            var input = pNode.node().getBoundingClientRect().width / (+anchor.attr("input") + 1);
            anchor.classed("end", false);
            activeLine.attr("to", pNode.attr("id"));
            activeLine.attr("input", anchor.attr("input"));
            activeLine.attr("end", input + ", 0");
        }
        activeLine = null;
        points.length = 0;
        translate = null;
    }

    function getTranslate(transform) {
        var arr = transform.substring(transform.indexOf("(")+1, transform.indexOf(")")).split(",");
        return [+arr[0], +arr[1]];
    }

    var dx = 0;
    var dy = 0;
    var dragElem = null;
    function dragstarted() {
        var transform = d3.select(this).attr("transform");
        var translate = getTranslate(transform);
        dx = d3.event.x - translate[0];
        dy = d3.event.y - translate[1];
        dragElem = d3.select(this);
    }

    function dragged() {
        dragElem.attr("transform", "translate(" + (d3.event.x - dx) + ", " + (d3.event.y - dy) + ")");
        console.log("updateCable.............  ")
        updateCable(dragElem);
    }

    function updateCable(elem) {

        var bound = elem.node().getBoundingClientRect();
        var width = bound.width;
        var height = bound.height;
        var id = elem.attr("id");
        var transform = elem.attr("transform");
        var t1 = getTranslate(transform);


        // 更新输出线的位置

        d3.selectAll('path[from="' + id + '"]')
            .each(function() {
                var start = d3.select(this).attr("start").split(",");
                start[0] = +start[0] + t1[0];
                start[1] = +start[1] + t1[1];

                var path = d3.select(this).attr("d");
                var end = path.substring(path.lastIndexOf(" ") + 1).split(",");
                end[0] = +end[0];
                end[1] = +end[1];

                d3.select(this).attr("d", function() {
                    return "M" + start[0] + "," + start[1]
                        + " C" + start[0] + "," + (start[1] + end[1]) / 2
                        + " " + end[0] + "," +  (start[1] + end[1]) / 2
                        + " " + end[0] + "," + end[1];
                });
            });

        // 更新输入线的位置
        d3.selectAll('path[to="' + id + '"]')
            .each(function() {
                var path = d3.select(this).attr("d");
                var start = path.substring(1, path.indexOf("C")).split(",");
                start[0] = +start[0];
                start[1] = +start[1];

                var end = d3.select(this).attr("end").split(",");
                end[0] = +end[0] + t1[0];
                end[1] = +end[1] + t1[1];

                d3.select(this).attr("d", function() {
                    return "M" + start[0] + "," + start[1]
                        + " C" + start[0] + "," + (start[1] + end[1]) / 2
                        + " " + end[0] + "," +  (start[1] + end[1]) / 2
                        + " " + end[0] + "," + end[1];
                });
            });

    }

    function dragended() {
        dx = dy = 0;
        dragElem = null;
    }

    function addNode(svg, node) {
        var g = svg.append("g")
            .attr("class", "node")
            .attr("data-id", node.dataId)
            .attr("id", node.id)
            .attr("transform", 'translate(' + node.x + ', ' + node.y + ')');

        var rect = g.append("rect")
            .attr("rx", 5)
            .attr("ry", 5)
            .attr("stroke-width", 2)
            .attr("stroke", "#333")
            .attr("fill", "#fff");

        var bound = rect.node().getBoundingClientRect();
        var width = bound.width;
        var height = bound.height;

        // text
        g.append("text")
            .text(node.text)
            .attr("x", width / 2)
            .attr("y", height / 2)
            .attr("dominant-baseline", "central")
            .attr("text-anchor", "middle");

        // left icon
        g.append('text')
            .attr("x", 18)
            .attr("y", height / 2)
            .attr("dominant-baseline", "central")
            .attr("text-anchor", "middle")
            .attr('font-family', 'FontAwesome')
            .text('\uf1c0');

        // right icon
        g.append('text')
            .attr("x", width - 18)
            .attr("y", height / 2)
            .attr("dominant-baseline", "central")
            .attr("text-anchor", "middle")
            .attr('font-family', 'FontAwesome')
            .text('\uf00c');

        // input circle
        var inputs = node.inputs || 0;
        g.attr("inputs", inputs);
        for(var i = 0; i < inputs; i++) {
            g.append("circle")
                .attr("class", "input")
                .attr("input", (i + 1))
                .attr("cx", width * (i + 1) / (inputs + 1))
                .attr("cy", 0)
                .attr("r", 5);
        }

        // output circle
        var outputs = node.outputs || 0;
        g.attr("outputs", outputs);
        for(i = 0; i < outputs; i++) {
            g.append("circle")
                .attr("output", (i + 1))
                .attr("class", "output")
                .attr("cx", width * (i + 1) / (outputs + 1))
                .attr("cy", height)
                .attr("r", 5);
        }

        return g;
    }
</script>
</html>

安卓期末大作业—Android图书管理应用源代码(高分项目),个人经导师指导并认可通过的高分设计项目,评审分98分,项目中的源码都是经过本地编译过可运行的,都经过严格调试,确保可以运行!主要针对计算机相关专业的正在做大作业、毕业设计的学生和需要项目实战练习的学习者,资源项目的难度比较适中,内容都是经过助教老师审定过的能够满足学习、使用需求,如果有需要的话可以放心下载使用。 安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—Android图书管理应用源代码(高分项目)安卓期末大作业—And
本文以电动汽车销售策略为研究对象,综合运用层次分析法、决策树、皮尔逊相关性分析、BP神经网络及粒子群优化等多种方法,深入探讨了影响目标客户购买电动汽车的因素及相应的销售策略。研究结果显示,客户对合资品牌电动汽车的满意度为78.0887,对自主品牌的满意度为77.7654,对新势力品牌的满意度为77.0078。此外,研究还发现电池性能、经济性、城市居住年限、居住区域、工作单位、职务、家庭年收入、个人年收入、家庭可支配收入、房贷占比、车贷占比等因素对电动汽车销量存在显著影响。通过BP神经网络对目标客户的购买意愿进行预测,其预测数据拟合程度过80%,且与真实情况高度接近。基于研究结果,本文为销售部门提出了提高销量的建议,包括精准定位尚未购买电动汽车的目标客户群体,制定并实施更具针对性的销售策略,在服务难度提升不过5%的前提下,选择实施最具可行性和针对性的销售方案。 在研究过程中,层次分析法被用于对目标客户购买电动汽车的影响因素进行系统分析与评价;决策树模型则用于对缺失数据进行预测填充,以确保数据的完整性和准确性;BP神经网络用于预测目标客户的购买意愿,并对其预测效果进行评估;粒子群优化算法对BP神经网络模型进行优化,有效提升了模型的稳定性和预测能力;皮尔逊相关性分析用于探究不同因素与购买意愿之间的相关性。通过这些方法的综合运用,本文不仅揭示了影响电动汽车销量的关键因素,还为销售策略的优化提供了科学依据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值