简体   繁体   中英

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,

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM