Solved

Jquery, Sparklines in a Modal window

Posted on 2014-04-16
3
753 Views
Last Modified: 2014-04-17
We are using Magnific Popup, a jquery lightbox (http://dimsemenov.com/plugins/magnific-popup/) and trying to get jquery sparklines to show in the popup.

The sparklines show on the main page, but not in the popup.

We are using the inline div element to hold the contents of the popup and it is unhidden when the link is clicked on.

We will have multiple pop-ups data and multiple  sparklines within the pop-up.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<!-- jQuery 1.7.2+ or Zepto.js 1.0+ -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
<script src="/jquery.sparkline.min.js"></script> 
   <script type="text/javascript">
    $(function() {
        /** This code runs when everything has been loaded on the page */
        /* Inline sparklines take their values from the contents of the tag */
        $('.inlinesparkline').sparkline(); 

        /* Sparklines can also take their values from the first argument 
        passed to the sparkline() function */
        var myvalues = [10,8,5,7,4,4,1];
        $('.dynamicsparkline').sparkline(myvalues);

        /* The second argument gives options such as chart type */
        $('.dynamicbar').sparkline(myvalues, {type: 'bar', barColor: 'green'} );

        /* Use 'html' instead of an array of values to pass options 
        to a sparkline with data in the tag */
        $('.inlinebar').sparkline('html', {type: 'bar', barColor: 'red'} );
    });
    </script>
<link rel="stylesheet" href="/mag.css"> 
<style>
body {
	font-family: Arial,Helvetica,Sans-serif;
	font: 0.75em/160% "Lucida Grande","Lucida Sans Unicode",Helvetica,Arial,Verdana,sans-serif;
}
table.detail  
{
border:1px solid black;
padding:10px;
 border-spacing:10px;
   border-collapse:separate;
}
.white-popup {
  position: relative;
  background: #FFF;
  padding: 20px;
  width: auto;
  max-width: 1024px;
  margin: 20px auto;
}

</style>

</head>

<body>
<table>
<tr>
<td><a href="#test-popup-cl-SVXY" class="open-popup-link">SVXY</a> </td>
</tr>
</table>
<div id="test-popup-cl-SVXY" class="white-popup mfp-hide">
<p><h2>Test Data </h2> </p>
<table>
<tr><th>Filed</th><th>Owner</th><th style="text-align:right">Shares</th><th style="text-align:right">Value<br> (Millions)</th></tr>
<tr><td>2014-04-15</td><td>Bb&T Securities, Llc</td><td style="text-align:right">4,000</td><td style="text-align:right">2</td></tr>
<tr><td>2014-02-19</td><td>Arbiter Partners Capital Management Llc</td><td style="text-align:right">98,400</td><td style="text-align:right">13</td></tr>
<tr><td>2014-02-14</td><td>Walleye Trading Llc</td><td style="text-align:right">1,600</td><td style="text-align:right">0</td></tr>
<tr><td>2014-02-14</td><td>Wolverine Asset Management Llc</td><td style="text-align:right">2,223</td><td style="text-align:right">6</td></tr>
<tr><td>2014-02-13</td><td>Susquehanna International Group, Llp</td><td style="text-align:right">1,418,400</td><td style="text-align:right">191</td></tr>
<tr><td>2014-02-13</td><td>Barclays Plc</td><td style="text-align:right">65,300</td><td style="text-align:right">8</td></tr>
<tr><td>2014-02-03</td><td>Spot Trading L.L.C</td><td style="text-align:right">32,300</td><td style="text-align:right">4</td></tr>
</table>
<p>
Inline Sparkline: <span class="inlinesparkline">1,4,4,7,5,9,10</span>.
</p>
<p>
Sparkline with dynamic data: <span class="dynamicsparkline">Loading..</span>
</p>
<p>
Bar chart with dynamic data: <span class="dynamicbar">Loading..</span>
</p>
<p>
Bar chart with inline data: <span class="inlinebar">1,3,4,5,3,5</span>
</p>
</div>
<p>
Inline Sparkline: <span class="inlinesparkline">1,4,4,7,5,9,10</span>.
</p>
<p>
Sparkline with dynamic data: <span class="dynamicsparkline">Loading..</span>
</p>
<p>
Bar chart with dynamic data: <span class="dynamicbar">Loading..</span>
</p>
<p>
Bar chart with inline data: <span class="inlinebar">1,3,4,5,3,5</span>
</p>
<!-- Magnific Popup core JS file -->
<script src="/mag.js"></script> 
<script type="text/javascript">
$('.open-popup-link').magnificPopup({
  type:'inline',
  midClick: true 
});
</script>
</body></html>

Open in new window

model-test.png
0
Comment
Question by:freshgrill
  • 2
3 Comments
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 40005943
The issue is that sparklines don't display on hidden elements refer here
http://omnipotent.net/jquery.sparkline/#hidden

You need to change the script at the bottom of your file to
<script type="text/javascript">
$('.open-popup-link').magnificPopup({
  type:'inline',
  midClick: true,
  callbacks: {
    open: function() {
      $.sparkline_display_visible()
    },
  }  
});
</script>

Open in new window

0
 

Author Closing Comment

by:freshgrill
ID: 40006766
Worked perfectly.
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 40006844
Excellent - thanks for the points.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now