How to style navigator dragging handles , Highstock

若如初见. 提交于 2019-12-31 05:37:08

问题


Appart from colors, is it possible to style the navigator handles(like shape, height, width, border radius, background, etc..).

From he API doc: http://api.highcharts.com/highstock#navigator.handles , I can only see backgroundColor and borderColor.

If the options is not supported, is there a way to dramatically replace it from some callback events?

The style I want is like:


回答1:



Update: Since v6.0.0 the handles are customizable through API options - https://api.highcharts.com/highstock/navigator.handles.symbols

Legacy solution below

It is possible to extend Highcharts and override Highcharts.Scroller.prototype.drawHandle function with a custom one. You could base your code on existing one and add more options and elements like in this example: http://jsfiddle.net/kuos06o5/1/ (for original question when Highstock version was 4.2.5)

$(function() {
  //custom handles
  (function(HC) {
    HC.Scroller.prototype.drawHandle = function(x, index) {
      var scroller = this,
        chart = scroller.chart,
        renderer = chart.renderer,
        elementsToDestroy = scroller.elementsToDestroy,
        handles = scroller.handles,
        handlesOptions = scroller.navigatorOptions.handles,
        radius = handlesOptions.radius,
        attr = {
          fill: handlesOptions.backgroundColor,
          stroke: handlesOptions.borderColor,
          'stroke-width': 1
        },
        tempElem,
        innerLinesOptions = handlesOptions.innerLines,
        h = innerLinesOptions.height;

      // create the elements
      if (!scroller.rendered) {
        // the group
        handles[index] = renderer.g('navigator-handle-' + ['left', 'right'][index])
          .css({
            cursor: 'ew-resize'
          })
          .attr({
            zIndex: 10 - index
          })
          .add();

        // cirlce
        tempElem = renderer.circle(0, 0, radius)
          .attr(attr)
          .add(handles[index]);
        elementsToDestroy.push(tempElem);

        // inner lines
        tempElem = renderer.path([
            'M', -1.5, -h / 2,
            'L', -1.5, h / 2,
            'M', 1.5, -h / 2,
            'L', 1.5, h / 2
          ])
          .attr({
            stroke: innerLinesOptions.color,
            'stroke-width': 1
          })
          .add(handles[index]);
        elementsToDestroy.push(tempElem);
      }

      // Place it
      handles[index][chart.isResizing ? 'animate' : 'attr']({
        translateX: scroller.scrollerLeft + scroller.scrollbarHeight + parseInt(x, 10),
        translateY: scroller.top + scroller.height / 2
      });
    };
  })(Highcharts);




  $('#container').highcharts('StockChart', {

    navigator: {
      handles: {
        backgroundColor: 'white',
        borderColor: 'grey',
        radius: 8,
        innerLines: {
          color: 'blue',
          height: 6
        }
      }
    },

    rangeSelector: {
      selected: 1
    },

    series: [{
      name: 'USD to EUR',
      data: usdeur
    }]
  });
});

In newer versions (4.2.6, 4.2.7 and 5.0.0 - current newest) drawHandle was moved, so the wrapper should start with:

    HC.Navigator.prototype.drawHandle = function(x, index) {

Demo: http://jsfiddle.net/kuos06o5/2/



来源:https://stackoverflow.com/questions/36570955/how-to-style-navigator-dragging-handles-highstock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!