vue-speedometer is a Vue component library for showing speedometer like gauge using d3.
NPM: npm install --save vue-speedometer
Yarn: yarn add vue-speedometer
source-js
// import the component
import VueSpeedometer from "vue-speedometer"
// and use it in your component like
export default {
components: { VueSpeedometer },
template: `<vue-speedometer />`,
}
vue-speedometer
is the name of the component to be used inside Vue templates
vue-speedometer
shares its core with react-d3-speedometer. For more info and context, please visit react-d3-speedometer
You can view Live Examples here
source-js
export default {
components: { VueSpeedometer },
template: `<vue-speedometer />`,
}
source-js
export default {
components: { VueSpeedometer },
template: `<vue-speedometer value="333" />`,
}
source-js
export default {
components: { VueSpeedometer },
template: `
<div>
<vue-speedometer
:maxSegmentLabels="12"
:segments="3"
:value="470"
:segmentColors='["tomato", "gold", "limegreen"]'
needleColor="lightgreen"
/>
</div>
`,
}
// startColor will be ignored
// endColor will be ignored
/>
source-js
export default {
components: { VueSpeedometer },
template: `
<div>
<vue-speedometer
:needleHeightRatio="0.7"
:maxSegmentLabels="5"
:segments="3"
:customSegmentStops="[0, 500, 750, 900, 1000]"
:segmentColors='["firebrick", "tomato", "gold", "limegreen"]'
:value="333"
/>
</div>
`,
}
// `segments` prop will be ignored since it will be calculated from `customSegmentStops`
// In this case there will be `4` segments (0-500, 500-750, 750-900, 900-1000)
/>
source-js
// Speedometer will take the width of the parent div (500)
// any width passed will be ignored
export default {
components: { VueSpeedometer },
data() {
return {
styles: {
width: "500px",
height: "300px",
background: "#EFEFEF",
},
}
},
template: `
<div :style="styles">
<vue-speedometer
:fluidWidth="true"
:minValue="100"
:maxValue="500"
:value="473"
needleColor="steelblue"
/>
<div>
Fluid width takes the width of the parent div (<strong>500px</strong> in this case)
</div>
</div>
`,
}
source-js
export default {
components: { VueSpeedometer },
template: `
<div>
<vue-speedometer
:value="333"
needleColor="steelblue"
:needleTransitionDuration="4000"
needleTransition="easeElastic"
/>
</div>
`,
}
source-js
// By default, when props change, only the value prop is updated and animated.
// This is to maintain smooth visualization and to ignore breaking appearance changes like segments, colors etc.
// You can override this behaviour by giving forceRender: true
export default {
components: { VueSpeedometer },
template: `
<div>
<vue-speedometer
:value="333"
:forceRender="true"
needleColor="steelblue"
:needleTransitionDuration="4000"
needleTransition="easeElastic"
/>
</div>
`,
}
source-js
export default {
components: { VueSpeedometer },
template: `
<div>
<vue-speedometer
:value="333"
:needleHeightRatio="0.5"
/>
</div>
`,
}
You can give a value between 0
and 1
to control the needle height.
source-js
export default {
components: { VueSpeedometer },
template: `
<div>
<vue-speedometer
:needleHeightRatio="0.7"
:maxSegmentLabels="5"
:segments="1000"
:value="333"
/>
</div>
`,
}
vue-speedometer
comes with a test suite using vue-test-utils.
ource-js
// navigate to root folder and run
npm test
// or 'yarn test' if you are using yarn
vue cli you are using the runtime only build of vue where the template compiler is not available
message when running from your local setup bootstrapped with vue-cli
. Basically create a vue.config.js
ource-js
// vue.config.js
module.exports = {
runtimeCompiler: true
}
v1.0.0.beta
Initial release. ref - https://codesandbox.io/s/vue-template-5yuw8PRs are welcome. Please create a issue/bugfix/feature branch and create an issue with your branch details. Probably I will create a similar branch in the upstream repo so that PRs can be raised against that branch instead of master
.
1.0
versions are compatible with Vue Version 2.x
For every subsequent major vue
upgrade, vue-speedometer
will be bumped to next major versions. For example 1.x
will be compatible with Vue 2.0
, 2.x
will be compatible with Vue 3.0
so on and so forth …Live Demo: https://palerdot.in/vue-speedometer/?path=/story/vue-speedometer--configuring-values
Download Link: https://github.com/palerdot/vue-speedometer/archive/master.zip
Official Website: https://github.com/palerdot/vue-speedometer
# Yarn
$ yarn add vue-speedometer
# NPM
$ npm install vue-speedometer --save
#vuejs #javascript #vue-js