简体   繁体   English

jqplot如何使链接到另一个页面的条形图可点击

[英]jqplot how to make bar graph clickable that links to another page

I've tried playing around with jqplot to create bar chart that can be clicked and then will redirect user to another page together with label value as url parameters but so for no luck to make a link. 我尝试使用jqplot创建条形图,该条形图可以单击,然后将用户连同标签值作为url参数一起重定向到另一个页面,但是没有运气可以建立链接。 This what I have done. 这是我所做的。

  $(document).ready(function() {
      $.jqplot.config.enablePlugins = true;

         var ticks = [ 'SCAN', 'SGON', 'TERM', 'TRAN'];
         var arrBranchId = ['08270K08001', '08298K08003', '12026K12003','14123K14003'];
         var plot1 = $.jqplot('chart1',[[0,0,0,1],[2,4,2,5],[0,0,0,1],[0,5,0,1]], {           
         seriesDefaults: {
                 renderer: $.jqplot.BarRenderer,
                 rendererOptions: { fillToZero: true },
                 pointLabels: { show: true }
             },

             series: [{label:'08270K08001'},{label:'08298K08003'},{label:'12026K12003'},{label:'14123K14003'}],

             legend: {
                 show: true,
                 placement: 'ne'
             },
             highlighter: {
             show: false,

             },
              cursor: {
                show: true
              },
             axes: {

                 xaxis: {
                     renderer: $.jqplot.CategoryAxisRenderer,
                     ticks: ticks
                 },

                 yaxis: {
                     renderer: $.jqplot.CategoryAxisRenderer,
                     pad: 1.05,
                     tickOptions: { formatString: '%d' }
                 }
             }
         });
     });
  • How should I make a link to the bar for example localhost/webCharts/branch.aspx?branchId=08270K08001 我应该如何链接到例如localhost / webCharts / branch.aspx的栏?branchId = 08270K08001

Also tried this How to catch the click event from the axis ticks jqplot, highcharts,flot , changed the function to become 还尝试过此方法如何从轴刻度jqplot,highcharts,flot捕获单击事件 ,将函数更改为

$('.jqplot-xaxis-tick').each(function(){
            var label = $(this),
                value = label.text();
            if(categoryLinks[value]) {
                label.click(function(){

                    alert('could link to another page: ' + categoryLinks[value]);
                });
            }
        });

but nothings happen when user click. 但是当用户点击时什么也没有发生。 Am i missing something here? 我在这里想念什么吗? Thanks in advance 提前致谢

I figured a way to make the bar clickable and link to another page by using window.location as follows 我想出了一种方法,使该栏可单击并通过使用window.location链接到另一个页面,如下所示

$('#chart1').bind('jqplotDataClick',function(ev, seriesIndex, pointIndex, data){
                window.location = 'branchDetails.aspx?appId='+ticks[**pointIndex**]+"&branchId="+arrBranchId[**seriesIndex**];          
        });

Noted : the array ticks[ ] and arrBranchId[ ] is already defined at $(document).ready(function() { ..... }. So I just passed the arrays with pointIndex and seriesIndex . Thank you very much everyone 注意:数组ticks []和arrBranchId []已经在$(document).ready(function(){.....}中定义了,所以我刚刚通过pointIndexseriesIndex传递了数组。非常感谢大家

I'm not sure if you are still looking for a solution but I found your question while researching the same problem. 我不确定您是否仍在寻找解决方案,但在研究相同问题时发现了您的问题。 I just figured out how to make it work. 我只是想出了如何使其工作。 Based on your code you should add a function something like this: 根据您的代码,您应该添加类似以下的功能:

$('#Chart1').bind('jqplotDataClick', function (ev, seriesIndex, pointIndex, data) {
    window.parent.location.href = 'YOURURL.aspx?id=' + arrBranchId[pointIndex];
});

Hopefully this will help you or someone else. 希望这对您或其他人有帮助。

Remove your each loop and use jqplot binding method, jqplotDataClick: 删除每个循环,并使用jqplot绑定方法jqplotDataClick:

// replace chart1 with your div ID
$('#chart1').bind('jqplotDataClick',
function (ev, seriesIndex, pointIndex, data) {
    // data contains the data point value, play with it
    // NOTE it may contain an array and not a string
    alert(data);
});

In the example above I'm using alert(data) you can use the data value to do anything else, ie redirect the user to a URL containing with the value passed as a parameter 在上面的示例中,我使用alert(data),您可以使用data值执行其他任何操作,即将用户重定向到包含以参数值传递的URL

Demo http://jsfiddle.net/fordlover49/JWhmQ/ 演示 http://jsfiddle.net/fordlover49/JWhmQ/

You can use this code snippet to get the click event ! 您可以使用此代码段获取click事件!

// Bind a listener to the "jqplotDataClick" event.  Here, simply change
  // the text of the info3 element to show what series and ponit were
  // clicked along with the data for that point.
  $('#chart3').bind('jqplotDataClick',
    function (ev, seriesIndex, pointIndex, data) {alert('clicked')
      $('#info3').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);
    }
  );

Check out this demo JSFIDDLE 看看这个演示JSFIDDLE

I found an easier method.. Keep it simple like this: 我找到了一种更简单的方法。

   $('#chart3').bind('jqplotDataClick', 
            function (ev, seriesIndex, pointIndex, data) {
                /* To open in a NEW window use: */
                /* window.open(data[2]); */
                /* To open in the same window use: */
                window.location.href='ErrorView3.php';
            }
  );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM