• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 891
  • Last Modified:

Jquery, Sparklines in a Modal window

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
freshgrill
Asked:
freshgrill
  • 2
1 Solution
 
Julian HansenCommented:
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
 
freshgrillAuthor Commented:
Worked perfectly.
0
 
Julian HansenCommented:
Excellent - thanks for the points.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now