Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <div id="app">
  <div class="line-chart unselectable">
    <svg width="622px" height="364px" viewBox="0 0 622 364" version="1.1">
      <defs>
        <circle id="circle" cx="10" cy="0" r="10"></circle>
        <filter x="-37.5%" y="-37.5%" width="175.0%" height="175.0%" filterUnits="objectBoundingBox" id="filter">
          <feOffset dx="0" dy="0" in="SourceAlpha" result="shadowOffsetOuter1"></feOffset>
          <feGaussianBlur stdDeviation="2.5" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
          <feColorMatrix values="0 0 0 0 0   0 0 0 0 0   0 0 0 0 0  0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
        </filter>
      </defs>
      <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
        <g transform="translate(-64.000000, -504.000000)">
          <g transform="translate(64.000000, 504.000000)">
            <g transform="translate(0.000000, 60.000000)" fill="#ECECEC">
              <rect transform="translate(28.000000, 123.500000) rotate(-270.000000) translate(-28.000000, -123.500000) " x="-94" y="123" width="244" height="1"></rect>
              <rect transform="translate(142.000000, 123.500000) rotate(-270.000000) translate(-142.000000, -123.500000) " x="20" y="123" width="244" height="1"></rect>
              <rect transform="translate(255.000000, 123.500000) rotate(-270.000000) translate(-255.000000, -123.500000) " x="133" y="123" width="244" height="1"></rect>
              <rect transform="translate(369.000000, 123.500000) rotate(-270.000000) translate(-369.000000, -123.500000) " x="247" y="123" width="244" height="1"></rect>
              <rect transform="translate(482.000000, 123.500000) rotate(-270.000000) translate(-482.000000, -123.500000) " x="360" y="123" width="244" height="1"></rect>
              <rect transform="translate(595.000000, 123.500000) rotate(-270.000000) translate(-595.000000, -123.500000) " x="473" y="123" width="244" height="1"></rect>
              <rect transform="translate(311.500000, 123.500000) scale(1, -1) translate(-311.500000, -123.500000) " x="28" y="123" width="567" height="1"></rect>
              <rect x="0" y="61" width="622" height="1"></rect>
              <rect x="0" y="183" width="622" height="1"></rect>
            </g>
            <g id="曲线" transform="translate(0, 60.000000)">
              <path :d="path" stroke="#47E0FF" stroke-width="6" stroke-linecap="round" transform="translate(10)"></path>
              <g :transform="'translate(' + value.x + ',' + value.y + ')'" v-for="(value, index) in valueArr" :key="index">
                <use fill="black" fill-opacity="1" filter="url(#filter)" xlink:href="#circle"></use>
                <use fill="#47E0FF" fill-rule="evenodd" xlink:href="#circle"></use>
              </g>
            </g>
          </g>
        </g>
      </g>
    </svg>
    <button @click="reload">Reload</button>
  </div>
</div>
              
            
!

CSS

              
                .line-chart {
  width: 100%;
  svg {
    margin: auto;
    display: block;
    max-width: 100%;
    width: 622px;
    height: 364px;
  }
}
button {
  display: block;
  margin: auto;
  outline:none;
  height: 40px;
  text-align: center;
  width: 130px;
  border-radius:40px;
  background: #fff;
  border: 2px solid #1ECD97;
  color: #1ECD97;
  letter-spacing:1px;
  text-shadow:0;
  font:{
    size:12px;
    weight:bold;
  }
  cursor: pointer;
  transition: all 0.25s ease;
  &:hover {
    color:white;
    background: #1ECD97;
  }
  &:active {
    //letter-spacing: 2px;
    letter-spacing: 2px ;
  }
}
              
            
!

JS

              
                function mapping (val, inputMin, inputMax, outputMin, outputMax) {
  return ((outputMax - outputMin) * ((val - inputMin) / (inputMax - inputMin))) + outputMin
}
function clone (obj) {
  return JSON.parse(JSON.stringify(obj))
}
const MAX_HEIGHT = 244
const MIN_HEIGHT = 0

function animate(time) {
    requestAnimationFrame(animate);
    TWEEN.update(time);
}
requestAnimationFrame(animate)

let valueArr = [
  {
    x: 0.136,
    y: 0
  },
  {
    x: 114.136,
    y: 0
  },
  {
    x: 227.136,
    y: 0
  },
  {
    x: 341.136,
    y: 0
  },
  {
    x: 454.136,
    y: 0
  },
  {
    x: 568.136,
    y: 0
  }
].map((item, index) => {
  return {
    ...item,
    y: MAX_HEIGHT * 0.5,
    startY: MIN_HEIGHT + (MAX_HEIGHT - MIN_HEIGHT) / 2,
    x: item.x + 18
  }
})
const DEFAULT_VALUE = clone(valueArr)
let animation = {
  progress: 0
}
new Vue({
  el: '#app',
  data () {
    return {
      valueArr,
      animation,
      duration: 1000,
      data: []
    }
  },
  watch: {
    data (val) {
      this.formatValues(val)
      this.doAnimation()
    }
  },
  mounted () {
    this.data = this.genRamdomValue()
  },
  computed: {
    path () {
      let steps = []
      this.valueArr.forEach((curr, index) => {
        if (index === 0) {
          // 移动到起点
          steps.push('M' + curr.x + ',' + curr.y)
        }
        if (index !== this.valueArr.length - 1) {
          let next = this.valueArr[index + 1]
          // 两个控制点坐标
          var ctrl1 = {
            x: (curr.x + next.x) * 0.5,
            y: curr.y
          }
          var ctrl2 = {
            x: ctrl1.x,
            y: next.y
          }
          steps.push('C' + ctrl1.x + ',' + ctrl1.y)
          steps.push(ctrl2.x + ',' + ctrl2.y)
          steps.push(next.x + ',' + next.y)
        }
      })
      return steps.join(' ')
    }
  },
  methods: {
    reload () {
       this.valueArr = clone(DEFAULT_VALUE)
       this.data = this.genRamdomValue()
    },
    genRamdomValue () {
      return this.valueArr.map(() => {
        return {
          value: Math.random()
        }
      })
    },
    formatValues (values) {
      this.valueArr.forEach((item, index) => {
        item.targetY = mapping(values[index].value, 0, 1, MIN_HEIGHT, MAX_HEIGHT)
      })
    },
    doAnimation () {
      animation.progress = 0
      new TWEEN.Tween(animation)
        .delay(1000)
        .to({progress: 1}, this.duration, TWEEN.Easing.Quadratic.Out)
        .onUpdate(this.onUpdate)
        .start()
    },
    onUpdate () {
      this.valueArr.forEach((item) => {
        item.y = item.startY + (item.targetY - item.startY) * this.animation.progress
      })
    }
  }
})
              
            
!
999px

Console