Browse Source

柱状图重写

feature
mk 2 years ago
parent
commit
fbad96fa2c
  1. 20
      src/assets/scss/modules/index.scss
  2. 176
      src/views/modules/home/index.vue

20
src/assets/scss/modules/index.scss

@ -356,28 +356,14 @@
height: calc(100% - 30px); height: calc(100% - 30px);
width: 100%; width: 100%;
overflow: hidden; overflow: hidden;
display: flex;
flex-direction: column;
.cnt { .cnt {
margin-top: 20px; margin-top: 20px;
display: flex; display: flex;
overflow: hidden; overflow: hidden;
height: 100%; height: 100%;
flex: 1;
.echart {
max-width: 115%;
max-height: 100%;
left: -30px;
top: 10px;
// margin-left: -50px;
position: absolute;
user-select: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
padding: 0px;
margin: 0px;
border-width: 0px;
}
.cnt-left { .cnt-left {
box-sizing: border-box; box-sizing: border-box;
padding: 16px; padding: 16px;

176
src/views/modules/home/index.vue

@ -93,7 +93,7 @@
</div> </div>
<div class="cnt"> <div class="cnt">
<!-- 树状图 --> <!-- 树状图 -->
<div class="echart" id="mychart" :style="myChartStyle"></div> <div class="echart" id="myBarchart" style="width: 100%; height: 100%;"></div>
<!-- 树状图end --> <!-- 树状图end -->
<!-- <div class="cnt-left"> <!-- <div class="cnt-left">
@ -336,8 +336,8 @@ export default {
noticeData: [], noticeData: [],
activeName: "resi", activeName: "resi",
myChart: {}, myChart: {},
myBarchart:{},
agencyLevel: '', agencyLevel: '',
xData: ["党员", "残疾人", "退役军人", "失业人员", "低保人员", "保障房人员", "特殊人员", "慢病人员", "老年人"],
yData: [ yData: [
// { // {
// value: 720, // value: 720,
@ -396,12 +396,13 @@ export default {
mounted() { mounted() {
// this.ehso(); // this.ehso();
// //
this.initEcharts();
this.getApiData(); this.getApiData();
this.$nextTick(() => { this.$nextTick(() => {
this.initChart() this.initChart()
this.initEcharts();
}) })
this.agencyLevel = localStorage.getItem("level", data.level); this.agencyLevel = localStorage.getItem("level", data.level);
console.log( console.log(
@ -484,6 +485,7 @@ export default {
handleWindowResize() { handleWindowResize() {
if (this.myChart) { if (this.myChart) {
this.myChart.resize(); this.myChart.resize();
this.myBarChart.resize();
} }
}, },
searchDataTab(str) { searchDataTab(str) {
@ -684,128 +686,62 @@ export default {
initEcharts() { initEcharts() {
this.$http.get("/actual/base/residentIntegrity/resiCategoryStats/byOrg/query4Org").then(({ data: { data } }) => { this.$http.get("/actual/base/residentIntegrity/resiCategoryStats/byOrg/query4Org").then(({ data: { data } }) => {
this.myChart = echarts.init(document.getElementById("my_chart")); this.myBarchart = echarts.init(document.getElementById("myBarchart"));
let xData = data.categoryStatsDatas.map(item => item.resiCategoryName)
this.yData = data.categoryStatsDatas.map(item => { let resiToal = data.categoryStatsDatas.map(item => item.total)
const total = Number(item.total); let nonIntegratedNum = data.categoryStatsDatas.map(item => item.nonIntegratedNum)
const nonIntegratedNum = Number(item.nonIntegratedNum); let option = {
let ratio = ''; backgroundColor: '#fff',
if (total !== 0) { color: ['#f7ca60', '#448cf6', ],
ratio = nonIntegratedNum / total; tooltip: {
} trigger: 'axis',
// console.log("nonIntegratedNum", nonIntegratedNum) axisPointer: {
// console.log("total", total) type: 'shadow'
return {
value: total,
itemStyle: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{ offset: 0, color: '#2D7DF2' },
{ offset: ratio, color: '#7EB1FE' },
{ offset: ratio, color: '#EFB632' },
{ offset: 1, color: '#FDD77D' }
],
global: false
},
shadowColor: "#91cc75",
borderType: "dashed",
// opacity: 0.5
} }
}; },
}); legend: {
// x: 'center',
const option = { bottom: '8%',
xAxis: { data: ['分类居民总数', '分类信息不完整数']
type: 'category', },
axisLabel: { grid: { //
// rotate: -45, top: '5%',
textStyle: { left: '3%',
fontSize: 10 right: '4%',
bottom: '20%',
containLabel: true
},
yAxis: [{
type: 'value',
splitLine: {
show: true,
lineStyle: {
color: ['#f2f2f2']
} }
}, },
axisTick: {
show: false, // x线
},
data: this.xData,
},
yAxis: {},
graphic: [{ //
type: 'group',
left: 'center',
bottom: 20,
z: 100,
children: [
{
type: 'rect',
left: 0,
// top: 'middle',
shape: {
width: 30,
height: 6,
},
style: {
fill: '#0056D6', //
},
},
{
type: 'text',
left: 35,
// top: 'middle',
style: {
text: '分类居民总数',
fill: '#333',
fontSize: 12,
// fontWeight: 'bold',
},
},
{
type: 'rect',
left: 130,
// top: 'middle',
shape: {
width: 30,
height: 6,
},
style: {
fill: '#FFDB84 ', //
},
},
{
type: 'text',
left: 170,
// top: 'middle',
style: {
text: '分类信息不完整数',
fill: '#333',
fontSize: 12,
// fontWeight: 'bold',
},
},
],
}], }],
series: [ xAxis: [{
{ type: 'category',
type: "bar", data: xData
barWidth: '30%', }],
barGap: '20%', series: [{
data: this.yData, name: '分类居民总数',
}, type: 'bar',
], stack: '总量',
barWidth: '30px',
data:resiToal ,
},
{
name: '分类信息不完整数',
type: 'bar',
stack: '总量',
data:nonIntegratedNum,
}
]
}; };
const myChart = echarts.init(document.getElementById("mychart")); this.myBarchart.setOption(option);
myChart.setOption(option); window.addEventListener("resize", this.handleWindowResize);
// myBarchart.on("click", (e) => {
window.addEventListener("resize", () => {
myChart.resize();
});
myChart.on("click", (e) => {
console.log("123123123112", e.name);
this.$router.push({ this.$router.push({
path: "/main/base-resi", path: "/main/base-resi",
query: { query: {

Loading…
Cancel
Save