highcharts - Slider on barchart -


with highcharts realized barchart. 1 show number of documents per year. select 1 or more dates, use slider located below graph. managed put in place. however, can not link chart. here, if put first cursor on 2000 , second on 2003, have graph should shows dates 2000, 2001, 2002, , 2003.

can me please ?

here html/php code :

<script src="https://code.highcharts.com/highcharts.js"></script> <script src="https://code.highcharts.com/modules/exporting.js"></script> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css"> <link rel="stylesheet" href="/resources/demos/style.css"> <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>  <div id="container"></div>  <div style="margin: 20px 0px 0px 60px">   <!--   "oninput" attribute automatically showing value of slider on load , whenever user changes value.   since using category x-axis, values between 0 , 12. example, i'm adding base year (2004)    output value shows label that's meaningful user. expand example more years, set max value   appropriate value , base year wherever plan start chart's data.   -->      <script>   $( function() {     $( "#slider-range" ).slider({       range: true,       min: 1960,       max: 2016,       values: [ 1960, 2016 ],       slide: function( event, ui ) {         $( "#amount" ).val( ui.values[ 0 ] + " - " + ui.values[ 1 ] );       }     });     $( "#amount" ).val( $( "#slider-range" ).slider( "values", 0 ) +       " - " + $( "#slider-range" ).slider( "values", 1 ) );   } );   </script>   <p>   <label for="amount">year(s):</label>   <input type="text" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;"> </p>  <div id="slider-range"></div> </div> 

and here js code :

$(function () {   $('#container').highcharts({     chart: {       type: 'column',       zoomtype: 'x'     },     colors:[       '#d8d826'     ],     legend:{       enabled:false     },     title:{       style:{         fontsize:'0px'       }     },     subtitle:{       style:{         fontsize:'0px'       }     },     xaxis: {         // note: there interesting bug here not labels shown when chart redrawn.       // i'm not why occuring, , i've tried different methods no avail. i'll check highcharts.       categories: ['1960','1961','1962','1963','1964','1965','1966','1967','1968','1969','1970','1971','1972','1973','1974','1975','1976','1977','1978','1979','1980','1981','1982','1983','1984','1985','1986','1987','1988','1989','1990','1991','1992','1993','1994','1995','1996','1997','1998','1999','2000','2001','2002','2003','2004','2005','2006','2007','2008','2009','2010','2011','2012','2013','2014','2015','2016'],       tickmarkplacement: 'on', tickinterval: 1,       minrange: 1   // set allow 1 year viewed     },     yaxis: {       min: 15,       title: {         text: 'number',         style:{           fontsize:'0px'         }       }     },     tooltip: {               shared: false,       usehtml: true     },     plotoptions: {       column: {         pointpadding: 0.2,         borderwidth: 0       }     },     series: [{       name: 'data year',       data: [49.9,83.6,48.9,69.1,83.6,40.9,69.9,83,28.9,40.9,81.6,24.9,46.4,49.9,83.6,48.9,69.1,83.6,40.9,69.9,83,28.9,40.9,81.6,24.9,46.4,49.9,83.6,48.9,69.1,83.6,40.9,69.9,83,28.9,40.9,81.6,24.9,46.4,49.9,83.6,48.9,69.1,83.6,40.9,69.9,83,28.9,40.9,81.6,24.9,46.4,49.9,83.6,48.9,69.1,50]     }]   });   }); 

you see result on : https://jsfiddle.net/uvat8u05/20/

the simple solution problem add jquery responsible slider inside load event callback function of chart, , use setextremes setting new extremes on slide: http://api.highcharts.com/highcharts#axis.setextremes

function(chart) {      $("#slider-range").slider({       range: true,       min: 1960,       max: 2016,       values: [1960, 2016],       slide: function(event, ui) {         $("#amount").val(ui.values[0] + " - " + ui.values[1]);         chart.xaxis[0].setextremes(ui.values[0] - 1960, ui.values[1] - 1960)       }     });     $("#amount").val($("#slider-range").slider("values", 0) +       " - " + $("#slider-range").slider("values", 1));    } 

here can find live example how can work: https://jsfiddle.net/uvat8u05/22/

regards,


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -