Ad
Irregular Slider In D3
I'm trying to build a slider in D3. I found a library for this https://github.com/johnwalley/d3-simple-slider which is perfect for the regular slider.
However, I need to slide by steps among irregularly spaced dates : [2002,2005,2012,2029] for example.
Do I need to build the slider by myself? Or do you know any other way?
Thank you,
Ad
Answer
The plugin you have chosen can work. See the example below. You need to add some customization.
<script src="https://d3js.org/d3.v5.js"></script>
<script src="https://unpkg.com/d3-simple-slider"></script>
<p id="value"></p>
<div id="slider"></div>
<script>
var data = [2002,2005,2012,2029];
var slider = d3
.sliderHorizontal()
.min(d3.min(data))
.max(d3.max(data))
.width(500)
.displayValue(false)
.on('onchange', val => {
d3.select('#value').text(val);
});
slider.tickValues(data)
.marks(data);
d3.select('#slider')
.append('svg')
.attr('width', 600)
.attr('height', 100)
.append('g')
.attr('transform', 'translate(30,30)')
.call(slider);
</script>
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad