【问题标题】:Trying to produce a pop up when the chart is clicked. The pop up is a close button单击图表时尝试生成弹出窗口。弹出是一个关闭按钮
【发布时间】:2016-04-13 04:19:53
【问题描述】:

当用户单击条形图时,我正在尝试在 highcharts 中生成一个弹出窗口。 到目前为止,我有代码,当用户单击一个栏时,它会淡化所有其他栏。我希望选择的栏在栏上方产生一个像这样的小弹出

when the close is selected it should highlight the bar and return all bars to normal state.

这是我的代码

javascript

$(function() {
$('#container4').highcharts({
    chart: {
        type: 'column',
        events: {
            click: function(e) {
                console.log(e);
            },
            selection: function(e) {
                console.log(e);
            }
        }
    },
    title: {
        text: ''
    },
    legend: {
        enabled: false
    },
    exporting: {
        enabled: false
    },
    credits: {
        enabled: false
    },
    xAxis: {
        gridLineColor: '',
        labels: {
            enabled: false
        }
    },
    yAxis: {
        title: {
            text: 'Fruit'
        },
        visible: false
    },
    credits: {
        enabled: false
    },
    plotOptions: {
        /*series: {
            allowPointSelect: true,
            states: {
                select: {
                    color: 'blue',
                }
            }
        },*/
        column: {
            stacking: 'normal',
        }
    },
    series: [{
        name: '',
        data: [-40, -60, -70, -80, -90, -100, -100, -100, -100, -100, -100],
        threshold: 0,
        color: '#E0E0E0 ',
        enableMouseTracking: false,
    }, {
        name: '',
        data: [-60, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50],
        threshold: 0,
        color: 'green',
        negativeColor: 'red',
    }, ]
});
 });

$(document).on('click', '.highcharts-tracker rect', function() {
var elm = $(this);
if (!elm.attr('class')) {
    $('.highcharts-tracker rect').removeAttr('class').css('opacity', 0.5);

    elm.attr('class', 'active').css('opacity', 1);
} else {
    $('.highcharts-tracker rect').removeAttr('class').css('opacity', 1);
}
});

css

.highcharts-series rect {
 transition:all .3s ease;
}

html

<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<div id="container4"></div>

【问题讨论】:

    标签: javascript jquery html angularjs highcharts


    【解决方案1】:

    $(function() {
      $('#container4').highcharts({
        chart: {
          type: 'column',
          events: {
            click: function(e) {
              console.log(e);
            },
            selection: function(e) {
              console.log(e);
            }
          }
        },
        title: {
          text: ''
        },
        legend: {
          enabled: false
        },
        exporting: {
          enabled: false
        },
        credits: {
          enabled: false
        },
        xAxis: {
          gridLineColor: '',
          labels: {
            enabled: false
          }
        },
        yAxis: {
          title: {
            text: 'Fruit'
          },
          visible: false
        },
        credits: {
          enabled: false
        },
        plotOptions: {
          /*series: {
          allowPointSelect: true,
          states: {
          select: {
          color: 'blue',
          }
          }
          },*/
          column: {
            stacking: 'normal',
          }
        },
        series: [{
          name: '',
          data: [-40, -60, -70, -80, -90, -100, -100, -100, -100, -100, -100],
          threshold: 0,
          color: '#E0E0E0 ',
          enableMouseTracking: false,
        }, {
          name: '',
          data: [-60, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50],
          threshold: 0,
          color: 'green',
          negativeColor: 'red',
        }, ]
      });
    });
    
    $(document).on('click', '.highcharts-tracker rect', function() {
      var elm = $(this);
      if (!elm.attr('class')) {
        $('.highcharts-tracker rect').removeAttr('class').css('opacity', 0.5);
        elm.attr('class', 'active').css('opacity', 1);
    
        $('#pointer').show().
        offset({
          top: elm.offset().top - 30,
          left: elm.offset().left + 10
        })
    
      }
    });
    
    $('#pointer').click(function() {
      $('.highcharts-tracker rect').removeAttr('class').css('opacity', 1);
      $(this).hide()
    })
    .highcharts-series rect {
      transition: all .3s ease;
    }
    
    #pointer {
      height: 30ph;
      width: 10px;
      display: noone;
      background-color: blue;
    }
    <script src="https://code.jquery.com/jquery-2.1.4.js"></script>
    <script src="http://code.highcharts.com/highcharts.js"></script>
    <div id="container4"></div>
    <div id="pointer">x</div>

    【讨论】:

    • 无论如何我可以用我给出的代码来实现它吗?它几乎是我需要的,但我希望用 highcharts 来实现它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多