Plugin Information

Attractive JavaScript charts for jQuery.

Plugin Name: Sparklines
Author: Gareth Watts
License: New BSD
Website: http://omnipotent.net/
Git Branch: gwatts/jquery.sparkline
Dependencies:
None Required
<script src="vendor/plugins/sparkline/jquery.sparkline.min.js"></script>

Basic Sparkline





Copy

<span class="inlinesparkline" data-spark-width="20%" data-spark-color="primary" values="5,6,7,9,9,5,3,2,2,4,6"></span>

<span class="inlinesparkline" data-spark-width="30%" data-spark-color="info" values="4,2,7,1,5,2,7,2,8,5,3"></span>

<span class="inlinesparkline" data-spark-width="40%" data-spark-color="warning" values="2,3,7,5,8,5,5,4,6,7,8"></span>
Copy

// Sparkline Color Library
var sparkColors = {
    "primary": [bgPrimary, bgPrimaryLr, bgPrimaryDr],
    "info": [bgInfo, bgInfoLr, bgInfoDr],
    "warning": [bgWarning, bgWarningLr, bgWarningDr],
    "success": [bgSuccess, bgSuccessLr, bgSuccessDr],
    "alert": [bgAlert, bgAlertLr, bgAlertDr]
};

// Sparklines Demo
$('.inlinesparkline').each(function(i, e) {

	// Set Sparkline Defaults
    var This = $(this);
    var Color = sparkColors["primary"];
    var Height = '35';
    var Width = '70%';
    This.children().remove();

    // Default color is "primary"
    // Color[0] = default shade
    // Color[1] = light shade
    // Color[2] = dark shade
    // User assigned color and height, else default
    var userColor = This.data('spark-color');
    var userHeight = This.data('spark-height');
    var userWidth = This.data('spark-width');
    if (userColor) {
        Color = sparkColors[userColor];
    }
    if (userHeight) {
        Height = userHeight;
    }
    if (userWidth) {
        Width = userWidth;
    }

    // Create Sparkline
    $(e).sparkline('html', {
        type: 'line',
        width: Width,
        height: Height,
        enableTagOptions: true,
        lineColor: Color[2], // Also tooltip icon color
        fillColor: Color[1],
        spotColor: Color[0],
        minSpotColor: Color[0],
        maxSpotColor: Color[0],
        highlightSpotColor: bgWarningDr,
        highlightLineColor: bgWarningLr
    });
});

Extended Information

For more detailed documentation you should refer to the plugins original documentation. Several additional resources have been listed below which contain further useful information.