vue+css实现柱状图表效果

代码语言:html

所属分类:图表

代码描述:vue+css实现柱状图表效果

代码标签: 图表 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<style>
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: #353445;
  color: #fff;
  font-family: system-ui;
}
.app {
  display: grid;
  height: 100vh;
}
.chart {
  margin: auto;
  max-width: 600px;
  height: 300px;
  display: -webkit-box;
  display: flex;
}
.plot {
   display: grid;
   grid-gap: 0.5rem;
  -webkit-box-align: end;
          align-items: end;
}
.bar {
  background: linear-gradient(to top, 	#FF4560 100px, #FEB019 200px, #00E396	 300px);
  border-radius: 1rem 1rem 0 0;
}
.x-axis {
  grid-row-start: 2;
  font-size: 0.75rem;
  display: contents;
}
.x-label {
  display: -webkit-inline-box;
  display: inline-flex;
  -webkit-writing-mode: vertical-lr;
      -ms-writing-mode: tb-lr;
          writing-mode: vertical-lr;
  white-space: nowrap;
  -webkit-transform: rotate(-180deg);
          transform: rotate(-180deg);
}
.y-axis {
  display: grid;
  margin-right: 1rem;
  height: 100%;
  grid-template-rows: repeat(10, minmax(0, 1fr));
  text-align: right;
  font-size: 0.75rem;
  line-height: 1;
}
</style>

</head>
<body translate="no">
<div class="app">
<div class="chart">
<div class="y-axis">
<div class="span" v-for="value in yLabels" :key="value">
{{value}}
</div>
</div>
<div class="plot" :style="styles">
<div :title="value" :style="getBarStyles(value)" class="bar" v-for="(value, index) in series" :key="index">
</div>
<div class="x-axis">
<span class="x-label" v-for="cat in categories" :key="cat">
{{cat}}
</span>
</div>
</div>
</div&g.........完整代码请登录后点击上方下载按钮下载查看

网友评论0