Select missing points display mode:


Description


This is an example of Javascript Chart Line series with missing data points. The type of the seriesGroups setting is set to line. You can see how the emptyPointsDisplay setting is used to display the missing data in different ways depending on the DropDownList values.

jQuery Chart: Line Series with missing points

JavaScript Chart line series with missing data points example.

A live JavaScript/jQuery example of jqxChart, the jQWidgets Chart component, with its complete source code below. It is one of 92 jqxChart demos for jQuery.

jqxChart API used in this demo

Source code

To run it in your own page, load jqx.base.css, a theme and the library files below from npm (npm install jqwidgets-scripts) or the jsDelivr CDN, then add the markup and the script. jQuery is not required: jqxcore.js provides $. Getting started with jqxChart shows the setup step by step.

The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxdata.js, jqxdraw.js, jqxchart.core.js, jqxbuttons.js, jqxlistbox.js, jqxscrollbar.js, jqxdropdownlist.js.

It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers).

script.js

$(document).ready(function () {
    var sampleData = [29, undefined, 10, 15, 10, undefined, NaN, 30, 25, undefined, 33, 19, 11];

    var settings = {
        title: "Line serie with missing points",
        description: 'Sample line serie with missing and invalid values',
        showLegend: true,
        padding: { left: 5, top: 5, right: 15, bottom: 5 },
        titlePadding: { left: 0, top: 0, right: 0, bottom: 10 },
        source: sampleData,
        xAxis:
        {
            text: 'x',
            valuesOnTicks: false
        },
        colorScheme: 'scheme05',
        seriesGroups:
            [
                {
                    type: 'line',
                    source: sampleData,
                    toolTipFormatFunction: function (value, itemIndex, serie, group, categoryValue, categoryAxis) {
                        var dataItem = sampleData[itemIndex];
                        return '<DIV style="text-align:left"><b>Index:</b> ' +
                                itemIndex + '<br /><b>Value:</b> ' +
                                value + '<br /></DIV>';
                    },
                    valueAxis:
                    {
                        title: { text: 'Value<br>' }
                    },
                    series:
                        [
                            { emptyPointsDisplay: 'skip', displayText: 'Value', lineWidth: 2, symbolSize: 8, symbolType: 'circle' }
                        ]
                }
            ]
    };

    // create the chart
    $("#chartContainer").jqxChart(settings);

    // get the chart's instance
    var chart = $('#chartContainer').jqxChart('getInstance');

    // series type drop down
    var modes = ["skip", "zero", "connect"];
    $("#dropDownMissingPointsMode").jqxDropDownList({ source: modes, selectedIndex: 0, width: '220', height: '25', dropDownHeight: 77 });

    $('#dropDownMissingPointsMode').on('select', function (event) {
        var args = event.args;
        if (args) {
            var value = args.item.value;

            chart.seriesGroups[0].series[0].emptyPointsDisplay = value;
            chart.update();
        }
    });
});

body.html

<div id="chartContainer" style="width:800px; height:500px"></div>
<p style="font-family: Verdana; font-size: 12px;">Select missing points display mode:
</p>
<div id="dropDownMissingPointsMode">
</div>

Learn more

More jQuery Chart demos