UNPKG

jqwidgets-framework

Version:

jQWidgets is an advanced Angular, Vue, Blazor, React, Web Components, jquery, ASP .NET MVC, Custom Elements and HTML5 UI framework.

161 lines (143 loc) 7.21 kB
<!DOCTYPE html> <html lang="en"> <head> <title id='Description'>JavaScript Chart Live Updates example</title> <meta name="description" content="This is an example of JavaScript Chart Series Live Updates." /> <link rel="stylesheet" href="../../../jqwidgets/styles/jqx.base.css" type="text/css" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1 minimum-scale=1" /> <script type="text/javascript" src="../../../scripts/jquery-1.12.4.min.js"></script> <script type="text/javascript" src="../../../jqwidgets/jqxcore.js"></script> <script type="text/javascript" src="../../../jqwidgets/jqxdata.js"></script> <script type="text/javascript" src="../../../jqwidgets/jqxdraw.js"></script> <script type="text/javascript" src="../../../jqwidgets/jqxchart.core.js"></script> <script type="text/javascript" src="../../../jqwidgets/jqxslider.js"></script> <script type="text/javascript" src="../../../jqwidgets/jqxbuttons.js"></script> <script type="text/javascript" src="../../../jqwidgets/jqxlistbox.js"></script> <script type="text/javascript" src="../../../jqwidgets/jqxscrollbar.js"></script> <script type="text/javascript" src="../../../jqwidgets/jqxdropdownlist.js"></script> <script type="text/javascript" src="../../../scripts/demos.js"></script> <script type="text/javascript"> $(document).ready(function () { var data = [ { a: 100, b: 200, c: 1 }, { a: 120, b: 140, c: 2 }, { a: 100, b: 110, c: 3 }, { a: 90, b: 135, c: 4 }, { a: 70, b: 210, c: 5 }, { a: 170, b: 210, c: 5 }, { a: 270, b: 350, c: 5 }, { a: 710, b: 410, c: 5 }, { a: 230, b: 305, c: 5 } ]; // prepare jqxChart settings var settings = { title: "Live updates demo", description: " ", enableAnimations: true, animationDuration: 1000, enableAxisTextAnimation: true, showLegend: true, padding: { left: 5, top: 5, right: 5, bottom: 5 }, titlePadding: { left: 0, top: 0, right: 0, bottom: 10 }, source: data, xAxis: { unitInterval: 1, gridLines: { interval: 2 }, valuesOnTicks: false }, valueAxis: { minValue: 0, maxValue: 1000, title: { text: 'Index Value' }, labels: { horizontalAlignment: 'right' } }, colorScheme: 'scheme03', seriesGroups: [ { type: 'column', columnsGapPercent: 50, alignEndPointsWithIntervals: true, series: [ { dataField: 'a', displayText: 'a', opacity: 1, lineWidth: 1, symbolType: 'circle', fillColorSymbolSelected: 'white', radius: 15 }, { dataField: 'b', displayText: 'b', opacity: 1, lineWidth: 1, symbolType: 'circle', fillColorSymbolSelected: 'white', radius: 15 } ] } ] }; // create the chart $('#chartContainer').jqxChart(settings); // get the chart's instance var chart = $('#chartContainer').jqxChart('getInstance'); // color scheme drop down var colorsSchemesList = ["scheme01", "scheme02", "scheme03", "scheme04", "scheme05", "scheme06", "scheme07", "scheme08"]; $("#dropDownColors").jqxDropDownList({ source: colorsSchemesList, selectedIndex: 2, width: '200', height: '25', dropDownHeight: 100 }); $('#dropDownColors').on('change', function (event) { var value = event.args.item.value; chart.colorScheme = value; chart.update(); }); // series type drop down var seriesList = ["splinearea", "spline", "column", "scatter", "stackedcolumn", "stackedsplinearea", "stackedspline"]; $("#dropDownSeries").jqxDropDownList({ source: seriesList, selectedIndex: 2, width: '200', height: '25', dropDownHeight: 100 }); $('#dropDownSeries').on('select', function (event) { var args = event.args; if (args) { var value = args.item.value; var isLine = value.indexOf('line') != -1; var isArea = value.indexOf('area') != -1; //chart.categoryAxis.valuesOnTicks = isLine || isArea; var group = chart.seriesGroups[0]; group.series[0].opacity = group.series[1].opacity = isArea ? 0.7 : 1; group.series[0].lineWidth = group.series[1].lineWidth = isLine ? 2 : 1; chart.seriesGroups[0].type = value; chart.update(); } }); // auto update timer var ttimer = setInterval(function () { var max = 800; for (var i = 0; i < data.length; i++) { data[i].a = Math.max(100, (Math.random() * 1000) % max); data[i].b = Math.max(100, (Math.random() * 1000) % max); } $('#chartContainer').jqxChart('update'); }, 3000); }); </script> </head> <body class='default'> <p> <div id='chartContainer' style="width: 850px; height: 500px"> </div> </p> <table style="width: 680px"> <tr> <td style="padding-left: 50px;"> <p style="font-family: Verdana; font-size: 12px;">Select the series type: </p> <div id='dropDownSeries'> </div> </td> <td> <p style="font-family: Verdana; font-size: 12px;">Select color scheme: </p> <div id='dropDownColors'> </div> </td> </tr> </table> <div class="example-description"> <br /> <h2>Description</h2> <br /> This is an example of JavaScript Chart Series Live Updates. The data changes every 3 seconds. You can choose the type of the series and the color scheme. The labels have horizontal alignment. </div> <div style="position: absolute; bottom: 5px; right: 5px;"> <a href="https://www.jqwidgets.com/" alt="https://www.jqwidgets.com/"><img alt="https://www.jqwidgets.com/" title="https://www.jqwidgets.com/" src="https://www.jqwidgets.com/wp-content/design/i/logo-jqwidgets.png"/></a> </div> </body> </html>