<template>
<div id="log"></div>
<div id="bar-chart-container"></div>
</template>
<style>
#g{
background: url("F:\vite-vue\public\背景.jpg");
background-repeat: no-repeat;
background-position: center;
height: 100%;
color: black;
width: 100%;
background-size: cover;
position: fixed;
opacity: 0.7;
}
#bar-chart-container{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url("F:\vite-vue\public\背景.jpg");
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
z-index: -1; /* 将背景图放在最底层 */
opacity: 0.5;
}
.tooltip{
background: #eed5a4;
line-height: 2;
opacity:0.8;
padding: 10px;
font-size: 15px;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
overflow: auto;
}
</style>
<script>
import { defineComponent } from 'vue';
import axios from "axios";
import * as d3 from "d3";
var color = d3.schemeCategory10;
export default defineComponent({
mounted() {
axios.get("caixi.json").then((res) => {
console.log(res.data);
this.drawGraphChart(res.data);
});
},
methods:{
drawGraphChart(data){
var width=(window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth);
var height=(window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight);
width=width*0.8;
height=height*0.9;
var color = d3.schemeCategory10;
var svg = d3.select("body") //选择<body>
.append("svg") //在<body>中添加<svg>
.attr("width", width) //设定<svg>的宽度属性
.attr("height", height);//设定<svg>的高度属性
var radius = width /2;
var tree=d3.cluster()
.size([2*Math.PI,radius-300]);
d3.json("caixi.json").then(function(data) {
console.log(data);
var hi=d3.hierarchy(data);
console.log(hi);
var root=tree(hi);
var links=root.links();
console.log(links);
var nodes=root.descendants();
console.log(nodes);
svg.append("g")
.attr("fill", "none")
.attr("stroke", "#555")
.attr("stroke-width", 1)
.selectAll("path")
.data(links)
.join("path")
.attr("d", d3.linkRadial()
.angle(d => d.x)
.radius(d => d.y));
svg.append("g")
.selectAll("circle")
.data(nodes)
.join("circle")
.attr("transform", d => `
rotate(${d.x * 180 / Math.PI - 90})
translate(${d.y},0)
`)
.attr("fill",d=>color[d.depth])
.attr("r", d=>(d.height*3+3))
.on("mouseenter",function(d,i)
{
const change=d3.select(this).attr("fill","white")
var t=change.attr("info")
tooltip.html("简介:"+t)
.style("visibility","visible")
})
.on("mouseleave",function(d,i)
{
const change=d3.select(this).attr("fill","#bb996e")
})
;
svg.append("g")
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.attr("stroke-width", 0)
.selectAll("text")
.data(root.descendants())
.join("text")
.attr("transform", d => `
rotate(${d.x * 180 / Math.PI - 90})
translate(${d.y},0)
rotate(${d.x >= Math.PI ? 180 : 0})
`)
.attr("dy", "0.31em")
.attr("x", d => d.x < Math.PI === !d.children ? 6 : -6)
.attr("text-anchor", d => d.x < Math.PI === !d.children ? "start" : "end")
.text(d => d.data.name)
.clone(true).lower()
.attr("fill", d=>color[d.depth]);
svg.selectAll("g")
.attr("transform", "translate(" + (width/2) + "," + (height/2) + ")");
var title = svg.append("text")
.text("中 国 菜 系")
.attr("x", 30)
.attr("y", 50)
.attr("font-size", "58")
.attr("fill", "black")
.style("writing-mode", "vertical-lr");
var shum = svg.append("text")
.text("20数科")
.attr("x", 65)
.attr("y", 330)
.attr("font-size", "12")
.attr("fill", "black")
.style("writing-mode", "vertical-lr");
})
}
}
})
</script>
<template>
<div id="log"></div>
<div id="bar-chart-container"></div>
</template>
<style>
#g{
background: url("F:\vite-vue\public\背景.jpg");
background-repeat: no-repeat;
background-position: center;
height: 100%;
color: black;
width: 100%;
background-size: cover;
position: fixed;
opacity: 0.7;
}
#bar-chart-container{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url("F:\vite-vue\public\背景.jpg");
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
z-index: -1; /* 将背景图放在最底层 */
opacity: 0.5;
}
.tooltip{
background: #eed5a4;
line-height: 2;
opacity:0.8;
padding: 10px;
font-size: 15px;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
overflow: auto;
}
</style>
<script>
import { defineComponent } from 'vue';
import axios from "axios";
import * as d3 from "d3";
var color = d3.schemeCategory10;
export default defineComponent({
mounted() {
axios.get("caixi.json").then((res) => {
console.log(res.data);
this.drawGraphChart(res.data);
});
},
methods:{
drawGraphChart(data){
var width=(window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth);
var height=(window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight);
width=width*0.8;
height=height*0.9;
var color = d3.schemeCategory10;
var svg = d3.select("body") //选择<body>
.append("svg") //在<body>中添加<svg>
.attr("width", width) //设定<svg>的宽度属性
.attr("height", height);//设定<svg>的高度属性
var radius = width /2;
var tree=d3.cluster()
.size([height,width*0.8]);
d3.json("caixi.json").then(function(data) {
console.log(data);
var hi=d3.hierarchy(data);
console.log(hi);
var root=tree(hi);
var links=root.links();
console.log(links);
var nodes=root.descendants();
console.log(nodes);
var gc=svg.append("g");
var lines=gc.selectAll("path")
.data(links)
.enter()
.append("path")
.attr("fill","none")
.attr("stroke","#eed5a4")
.attr("d",d3.linkHorizontal() //d3.linkHorizontal()
.x(d=>d.y+90)
.y(d=>d.x+10)
);
var tooltip=d3.select("body")
.append("div")
.attr("class","tooltip")
.attr("opacity",0.0);
var mynode=gc.selectAll("circle")
.data(nodes)
.join("circle")
.attr("cx",d=>d.y+110)
.attr("cy",d=>d.x+10)
.attr("r",d=>(d.height+2)*3)
.attr("fill","#bb996e")
.attr("stroke","white")
.attr("info",(d)=>d.data.intro)
.on("mouseenter",function(d,i)
{
const change=d3.select(this).attr("fill","white")
var t=change.attr("info")
tooltip.html("简介:"+t)
.style("visibility","visible")
})
.on("mouseleave",function(d,i)
{
const change=d3.select(this).attr("fill","#bb996e")
})
var nodetxt=gc.selectAll("text")
.data(nodes)
.join("text")
.attr("x",d=>d.y+110)
.attr("y",d=>d.x+20)
.attr("font-size","12")
.attr("fill","black")
.attr("transform",d=>`rotate(0,${d.x},${d.y})`)
.text(d=>d.data.name);
var title=gc.append("text")
.text("中国菜系")
.attr("x",width/2-200)
.attr("y",50)
.attr("font-size","48")
.attr("fill","black")
})
}
}
})
</script>
<template>
<div id="log"></div>
<div id="bar-chart-container"></div>
</template>
<style>
#g{
background: url("F:\vite-vue\public\背景.jpg");
background-repeat: no-repeat;
background-position: center;
height: 100%;
color: black;
width: 100%;
background-size: cover;
position: fixed;
opacity: 0.7;
}
#bar-chart-container{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url("F:\vite-vue\public\背景.jpg");
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
z-index: -1; /* 将背景图放在最底层 */
opacity: 0.5;
}
.tooltip{
background: #eed5a4;
line-height: 2;
opacity:0.8;
padding: 10px;
font-size: 15px;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
overflow: auto;
}
</style>
<script>
import { defineComponent } from 'vue';
import axios from "axios";
import * as d3 from "d3";
var color = d3.schemeCategory10;
export default defineComponent({
mounted() {
axios.get("caixi.json").then((res) => {
console.log(res.data);
this.drawGraphChart(res.data);
});
},
methods:{
drawGraphChart(data){
var width=(window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth);
var height=(window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight);
width=width*0.8;
height=height*0.9;
var color = d3.schemeCategory10;
var svg = d3.select("body") //选择<body>
.append("svg") //在<body>中添加<svg>
.attr("width", width) //设定<svg>的宽度属性
.attr("height", height);//设定<svg>的高度属性
var radius = width /2;
var tree=d3.cluster()
.size([width,height*0.7]);
d3.json("caixi.json").then(function(data) {
console.log(data);
var hi=d3.hierarchy(data);
console.log(hi);
var root=tree(hi);
var links=root.links();
console.log(links);
var nodes=root.descendants();
console.log(nodes);
var gc=svg.append("g");
var lines=gc.selectAll("path")
.data(links)
.enter()
.append("path")
.attr("fill","none")
.attr("stroke","#eed5a4")
.attr("d",d3.linkVertical() //d3.linkHorizontal()
.x(d=>d.x)
.y(d=>d.y+90)
);
var tooltip=d3.select("body")
.append("div")
.attr("class","tooltip")
.attr("opacity",0.0);
var mynode=gc.selectAll("circle")
.data(nodes)
.join("circle")
.attr("cx",d=>d.x)
.attr("cy",d=>d.y+90)
.attr("r",d=>(d.height+2)*3)
.attr("fill","#bb996e")
.attr("stroke","white")
.attr("info",(d)=>d.data.intro)
.on("mouseenter",function(d,i)
{
const change=d3.select(this).attr("fill","white")
var t=change.attr("info")
tooltip.html("简介:"+t)
.style("visibility","visible")
})
.on("mouseleave",function(d,i)
{
const change=d3.select(this).attr("fill","#bb996e")
})
var nodetxt=gc.selectAll("text")
.data(nodes)
.join("text")
.attr("x",d=>d.x+95)
.attr("y",d=>d.y-10)
.attr("font-size","15")
.attr("fill","black")
.attr("transform",d=>`rotate(90,${d.x},${d.y})`)
.text(d=>d.data.name);
var title=gc.append("text")
.text("中国菜系")
.attr("x",width/2-200)
.attr("y",50)
.attr("font-size","48")
.attr("fill","black")
})
}
}
})
</script>