d3实现水果分类计数统计饼状图效果代码
代码语言:html
所属分类:其他
代码描述:d3实现水果分类计数统计饼状图效果代码,选择水果类型,输入数值,进行汇总统计。
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
@import url("https://fonts.googleapis.com/css?family=IBM+Plex+Mono:400,700&display=swap");
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
body {
color: hsl(240, 25%, 95%);
background: hsl(240, 25%, 20%);
font-family: "IBM Plex Mono", monospace;
}
/* absolute position the span in the top left corner of each heading */
h2 {
position: relative;
font-size: 1.85rem;
padding: 0.25rem;
font-weight: 400;
}
h2 span {
position: absolute;
top: 0%;
right: 100%;
transform: translateY(-50%);
display: block;
width: 1.25em;
height: 1.25em;
border-radius: 0.75rem;
background: hsla(240, 25%, 50%, 0.3);
}
h2 span svg {
display: block;
width: 100%;
height: 100%;
filter: drop-shadow(0 0 3px hsla(240, 25%, 0%, 0.5));
}
.app > * + * + * {
margin-top: 5rem;
}
section > * + * {
margin-top: 1rem;
}
.app.svelte-bshi3b{max-width:900px;width:80vw;margin:2rem auto}
form.svelte-12oa6ic{display:flex;flex-wrap:wrap;align-items:center;color:hsl(240, 25%, 20%);background:hsla(240, 25%, 95%, 1);padding:0.75rem 1rem;border-radius:5px}form.svelte-12oa6ic label.svelte-12oa6ic{flex-grow:1;display:flex;flex-direction:column;font-size:1rem;line-height:2}form.svelte-12oa6ic label input.svelte-12oa6ic{font-size:1.1rem;color:inherit;font-family:inherit;background:none;border:none;padding:0.5rem 0.75rem;border-left:0.25rem solid currentColor}form.svelte-12oa6ic button.svelte-12oa6ic{background:none;border:none;color:inherit;width:3rem;height:3rem;padding:0.25rem;margin:0.25rem 0}form.svelte-12oa6ic button svg.svelte-12oa6ic{display:block;width:100%;height:100%}
main.svelte-m9wvyg{display:grid;justify-content:center;grid-template-columns:repeat(auto-fill, 150px);grid-auto-rows:150px;grid-gap:2rem}article.svelte-m9wvyg{display:flex;flex-direction:column;justify-content:center;align-items:center;background:hsla(240, 25%, 50%, 0.1);border:5px solid currentColor;border-radius:25px;position:relative}article.svelte-m9wvyg h2.svelte-m9wvyg{font-weight:400;font-size:1.25rem}article.svelte-m9wvyg p.svelte-m9wvyg{font-size:2.25rem;font-weight:700}article.svelte-m9wvyg button.svelte-m9wvyg{position:absolute;top:0%;right:0%;transform:translate(50%, -50%);background:none;border:none;border-radius:50%;width:1.5rem;height:1.5rem;color:inherit;background:currentColor;box-shadow:0 0 0 0.5rem hsl(240, 25%, 20%)}article.svelte-m9wvyg button svg.svelte-m9wvyg{display:block;width:100%;height:100%;color:hsl(240, 25%, 20%)}
div.svelte-1ljjwhb{display:flex;justify-content:space-around;flex-wrap:wrap;align-items:center}
</style>
</head>
<body>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/d3.v5.js"></script>
<script >
var app = function() {
"use strict";
function e() {}
function t(e) {
return e()
}
function n() {
return Object.create(null)
}
function r(e) {
e.forEach(t)
}
function i(e) {
return "function" == typeof e
}
function o(e, t) {
return e != e ? t == t : e !== t || e && "object" == typeof e || "function" == typeof e
}
function l(e, t, n) {
e.$$.on_destroy.push(function(e, t) {
const n = e.subscribe(t);
return n.unsubscribe ? ()=>n.unsubscribe() : n
}(t, n))
}
function a(e, t) {
e.appendChild(t)
}
function s(e, t, n) {
e.insertBefore(t, n || null)
}
function c(e) {
e.parentNode.removeChild(e)
}
function u(e, t) {
for (let n = 0; n < e.length; n += 1)
e[n] && e[n].d(t)
}
function d(e) {
return document.createElement(e)
}
function m(e) {
return document.createElementNS("http://www.w3.org/2000/svg", e)
}
function f(e) {
return document.createTextNode(e)
}
function h() {
return f(" ")
}
function p() {
return f("")
}
function g(e, t, n, r) {
return e.addEventListener(t, n, r),
()=>e.removeEventListener(t, n, r)
}
function v(e, t, n) {
null == n ? e.removeAttribute(t) : e.setAttribute(t, n)
}
function $(e, t) {
t = "" + t,
e.data !== t && (e.data = t)
}
function y(e, t) {
(null != t || e.value) && (e.value = t)
}
function b(e, t, n, r) {
e.style.setProperty(t, n, r ? "important" : "")
}
let w;
function x(e) {
w = e
}
const k = []
, _ = []
, S = []
, M = []
, F = Promise.resolve();
let B = !1;
function C(e) {
S.push(e)
}
function L() {
const e = new Set;
do {
for (; k.length; ) {
const e = k.shift();
x(e),
j(e.$$)
}
for (; _.length; )
_.pop()();
for (let t = 0; t < S.length; t += 1) {
const n = S[t];
e.has(n) || (n(),
e.add(n))
}
S.length = 0
} while (k.length);
for (; M.length; )
M.pop()();
B = !1
}
function j(e) {
e.fragment && (e.update(e.dirty),
r(e.before_update),
e.fragment.p(e.dirty, e.ctx),
e.dirty = null,
e.after_update.forEach(C))
}
const O = new Set;
let E;
function T(e, t) {
e && e.i && (O.delete(e),
e.i(t))
}
function A(e, t, n, r) {
if (e && e.o) {
if (O.has(e))
return;
O.add(e),
E.c.push(()=>{
O.delete(e),
r && (n && e.d(1),
r())
}
),
e.o(t)
}
}
function H(e, t) {
e.d(1),
t.delete(e.key)
}
function N(e, t, n, r, i, o, l, a, s, c, u, d) {
let m = e.length
, f = o.length
, h = m;
const p = {};
for (; h--; )
p[e[h].key] = h;
const g = []
, v = new Map
, $ = new Map;
for (h = f; h--; ) {
const e = d(i, o, h)
, a = n(e);
let s = l.get(a);
s ? r && s.p(t, e) : (s = c(a, e)).c(),
v.set(a, g[h] = s),
a in p && $.set(a, Math.abs(h - p[a]))
}
const y = new Set
, b = new Set;
function w(e) {
T(e, 1),
e.m(a, u),
l.set(e.key, e),
u = e.first,
f--
}
for (; m && f; ) {
const t = g[f - 1]
, n = e[m - 1]
, r = t.key
, i = n.key;
t === n ? (u = t.first,
m--,
f--) : v.has(i) ? !l.has(r) || y.has(r) ? w(t) : b.has(i) ? m-- : $.get(r) > $.get(i) ? (b.add(r),
w(t)) : (y.add(i),
m--) : (s(n, l),
m--)
}
for (; m--; ) {
const t = e[m];
v.has(t.key) || s(t, l)
}
for (; f; )
w(g[f - 1]);
return g
}
function I(e, n, o) {
const {fragment: l, on_mount: a, on_destroy: s, after_update: c} = e.$$;
l.m(n, o),
C(()=>{
const n = a.map(t).filter(i);
s ? s.push(...n) : r(n),
e.$$.on_mount = []
}
),
c.forEach(C)
}
function q(e, t) {
e.$$.fragment && (r(e.$$.on_destroy),
e.$$.fragment.d(t),
e.$$.on_destroy = e.$$.fragment = null,
e.$$.ctx = {})
}
function P(e, t) {
e.$$.dirty || (k.push(e),
B || (B = !0,
F.then(L)),
e.$$.dirty = n()),
e.$$.dirty[t] = !0
}
function z(t, i, o, l, a, s) {
const c = w;
x(t);
const u = i.props || {}
, d = t.$$ = {
fragment: null,
ctx: null,
props: s,
update: e,
not_equal: a,
bound: n(),
on_mount: [],
on_destroy: [],
before_update: [],
after_update: [],
context: new Map(c ? c.$$.context : []),
callbacks: n(),
dirty: null
};
let m = !1;
var f;
d.ctx = o ? o(t, u, (e,n,r=n)=>(d.ctx && a(d.ctx[e], d.ctx[e] = r) && (d.bound[e] && d.bound[e](r),
m && P(t, e)),
n)) : u,
d.update(),
m = !0,
r(d.before_update),
d.fragment = l(d.ctx),
i.target && (i.hydrate ? d.fragment.l((f = i.target,
Array.from(f.childNodes))) : d.fragment.c(),
i.intro && T(t.$$.fragment),
I(t, i.target, i.anchor),
L()),
x(c)
}
class D {
$destroy() {
q(this, 1),
this.$destroy = e
}
$on(e, t) {
const n = this.$$.callbacks[e] || (this.$$.callbacks[e] = []);
return n.push(t),
()=>{
const e = n.indexOf(t);
-1 !== e && n.splice(e, 1)
}
}
$set() {}
}
function R(t) {
var n, r, i, o, l, u, d, f, h, p, g, $, y, w, x, k, _, S, M, F, B, C, L, j, O;
return {
c() {
n = m("svg"),
r = m("symbol"),
i = m("g"),
o = m("path"),
l = m("symbol"),
u = m("g"),
d = m("g"),
f = m("path"),
h = m("circle"),
p = m("path"),
g = m("symbol"),
$ = m("g"),
y = m("path"),
w = m("path"),
x = m("path"),
k = m("symbol"),
_ = m("g"),
S = m("g"),
M = m("g"),
F = m("path"),
B = m("symbol"),
C = m("g"),
L = m("path"),
j = m("path"),
O = m("path"),
v(o, "d", "M 50 35 v 30 m -15 -15 h 30"),
v(i, "fill", "none"),
v(i, "stroke", "currentColor"),
v(i, "stroke-width", "7"),
v(i, "stroke-linecap", "round"),
v(r, "id", "add"),
v(f, "d", "M -20 0 h -37.5 a 15 15 0 0 0 -15 15 v 42.5 a 15 15 0 0 0 15 15 h 42.5 a 15 15 0 0 0 15 -15 v -37.5"),
v(h, "cx", "0"),
v(h, "cy", "0"),
v(h, "r", "20"),
v(p, "stroke-width", "5"),
v(p, "d", "M 0 -7 v 14 m -7 -7 h 14"),
v(d, "transform", "translate(76 24)"),
v(u, "fill", "none"),
v(u, "stroke", "currentColor"),
v(u, "stroke-width", "7"),
v(u, "stroke-linecap", "round"),
v(l, "id", "create"),
v(y, "d", "M 50 35 h 20"),
v(w, "d", "M 30 50 h 40"),
v(x, "d", "M 30 65 h 20"),
v($, "fill", "none"),
v($, "stroke", "currentColor"),
v($, "stroke-width", "7"),
v($, "stroke-linecap", "round"),
v(g, "id", "list"),
v(F, "d", "M 0 -20 v 40 m -20 -20 h 40"),
v(M, "fill", "none"),
v(M, "stroke", "currentColor"),
v(M, "stroke-width", "10"),
v(M, "stroke-linecap", "round"),
v(S, "transform", "rotate(45)"),
v(_, "transform", "translate(50 50)"),
v(k, "id", "delete"),
.........完整代码请登录后点击上方下载按钮下载查看
网友评论0