javascript highchart photo slide

2019-02-28 15:10发布

I'm creating a visual chart using the javascript library highchart. Ive created my chart with some fake data. I want to know how to use the chart data to trigger an image slide. So if i hover on the data on a certain point in the chart, a corresponding image will slide horizontally to the center of the page. Here is some of my javascript code so far.

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>

        <div id="container" style="width:100%; height:400px;"></div>
            <script type="text/javascript">
$(function () {
    $('#container').highcharts({
        title: {
            text: 'Dive Log',
            x: -20 //center
        },
        subtitle: {
            text: 'example',
            x: -20
        },
        xAxis: {
            title: {
                text: 'Time',
            categories: ['5', '10', '15', '20', '25', '30',
                '35', '40', '45', '50', '55', '1 hr']
            }
        },
        yAxis: {
            title: {
                text: 'Depth in Meters'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            valueSuffix: '°C'
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle',
            borderWidth: 0
        },
        series: [ {
            data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
        }], 

    });
});     
</script>   

1条回答
乱世女痞
2楼-- · 2019-02-28 15:31

You can do it by using events.mouseOver and events.MouseOut on your series points: http://api.highcharts.com/highcharts#plotOptions.series.point.events.mouseOver http://api.highcharts.com/highcharts#plotOptions.series.point.events.mouseOut

Inside its callback function you can trigger 'slide' to your image:

      events: {
            mouseOver: function () {
                $(".img1").trigger("slideIn");
            },
            mouseOut: function () {
                $(".img1").trigger("slideOut");
            },
        }

and in your jQuery you can watch for your trigger options, for example:

$('.img1').on("slideIn", function () {
        $(this).animate({
            opacity: 1,
            left: 155
        });
    });

    $('.img1').on("slideOut", function () {
        $(this).animate({
            opacity: 0,
            left: -550
        });
    });

example: http://jsfiddle.net/izothep/gf48mmfa/4/

查看更多
登录 后发表回答