【问题标题】:javascript highchart photo slidejavascript highchart 照片幻灯片
【发布时间】:2015-10-28 14:28:01
【问题描述】:

我正在使用 javascript 库 highchart 创建一个可视化图表。我用一些假数据创建了我的图表。我想知道如何使用图表数据来触发图像幻灯片。因此,如果我将鼠标悬停在图表中某个点的数据上,相应的图像将水平滑动到页面中心。到目前为止,这是我的一些 javascript 代码。

<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>   

【问题讨论】:

    标签: javascript jquery html css highcharts


    【解决方案1】:

    您可以通过在系列点上使用 events.mouseOver 和 events.MouseOut 来做到这一点: http://api.highcharts.com/highcharts#plotOptions.series.point.events.mouseOver http://api.highcharts.com/highcharts#plotOptions.series.point.events.mouseOut

    在其回调函数中,您可以触发“滑动”到您的图像:

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

    在你的 jQuery 中你可以观察你的触发选项,例如:

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

    示例: http://jsfiddle.net/izothep/gf48mmfa/4/

    【讨论】:

    • 非常感谢,太棒了!
    • 如果我想将参数添加到 y 轴以触发单独的文件照片幻灯片,我在事件之前添加它?我对 javascript 有点陌生
    • @jsandrails 你能解释一下你的意思吗?目前 y 轴的参数与照片幻灯片的触发无关。是否要添加更多图像并允许更多/所有点触发滑动?
    • 是的,就是这样,添加更多图像并触发滑动。我知道该怎么做,但它不起作用,我知道它在我的括号里。
    猜你喜欢
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-04
    • 1970-01-01
    • 2013-11-06
    • 1970-01-01
    相关资源
    最近更新 更多