c# - Flot Ajax Realtime Chart Not get data from CS Page -
c# - Flot Ajax Realtime Chart Not get data from CS Page -
i'm trying illustration of flot ajax realtime chart info coming cs page info not getting passed. chart gets created info points don't show up. missing?
default.aspx
<%@ page title="flot examples: real-time updates" language="c#" masterpagefile="~/site.master" autoeventwireup="true" codefile="default.aspx.cs" inherits="_default" %> <asp:content id="bodycontent" contentplaceholderid="maincontent" runat="server"> <script type="text/javascript" src="js/flot/jquery.min.js"></script> <script type="text/javascript" src="js/flot/jquery.flot.js"></script> <script type="text/javascript" src="js/flot/jquery.flot.min.js"></script> <script type="text/javascript" src="js/flot/jquery.flot.time.js"></script> <script type="text/javascript" src="js/flot/jquery.flot.axislabels.js"></script> <script type="text/javascript" src="js/flot/jshashtable-2.1.js"></script> <script type="text/javascript" src="js/flot/jquery.numberformatter-1.2.3.min.js"></script> <script type="text/javascript" src="js/flot/jquery.flot.symbol.js"></script> <!-- javascript --> <script type="text/javascript"> var cpu = [], cpucore = [], disk = []; var dataset; var totalpoints = 100; var updateinterval = 5000; var = new date().gettime(); var options = { series: { lines: { linewidth: 1.2 }, bars: { align: "center", fillcolor: { colors: [{ opacity: 1 }, { opacity: 1}] }, barwidth: 500, linewidth: 1 } }, xaxis: { mode: "time", ticksize: [60, "second"], tickformatter: function (v, axis) { var date = new date(v); if (date.getseconds() % 20 == 0) { var hours = date.gethours() < 10 ? "0" + date.gethours() : date.gethours(); var minutes = date.getminutes() < 10 ? "0" + date.getminutes() : date.getminutes(); var seconds = date.getseconds() < 10 ? "0" + date.getseconds() : date.getseconds(); homecoming hours + ":" + minutes + ":" + seconds; } else { homecoming ""; } }, axislabel: "time", axislabelusecanvas: true, axislabelfontsizepixels: 12, axislabelfontfamily: 'verdana, arial', axislabelpadding: 10 }, yaxes: [ { min: 0, max: 100, ticksize: 5, tickformatter: function (v, axis) { if (v % 10 == 0) { homecoming v + "%"; } else { homecoming ""; } }, axislabel: "cpu loading", axislabelusecanvas: true, axislabelfontsizepixels: 12, axislabelfontfamily: 'verdana, arial', axislabelpadding: 6 }, { max: 5120, position: "right", axislabel: "disk", axislabelusecanvas: true, axislabelfontsizepixels: 12, axislabelfontfamily: 'verdana, arial', axislabelpadding: 6 } ], legend: { nocolumns: 0, position:"nw" }, grid: { backgroundcolor: { colors: ["#ffffff", "#edf5ff"] } } }; function initdata() { (var = 0; < totalpoints; i++) { var temp = [now += updateinterval, 0]; cpu.push(temp); cpucore.push(temp); disk.push(temp); } } function getdata() { //set no cache $.ajaxsetup({ cache: false }); $.ajax({ url: 'default.aspx', datatype: 'json', success: update, error: function () { settimeout(getdata, updateinterval); } }); } var temp; function update(_data) { //remove first item of array cpu.shift(); cpucore.shift(); disk.shift(); += updateinterval //add info retrieve backend array temp = [now, _data.cpu]; cpu.push(temp); temp = [now, _data.core]; cpucore.push(temp); temp = [now, _data.disk]; disk.push(temp); //update legend label users can see latest value in legend dataset = [ { label: "cpu:" + _data.cpu + "%", data: cpu, lines: { fill: true, linewidth: 1.2 }, color: "#00ff00" }, { label: "disk:" + _data.disk + "kb", data: disk, color: "#0044ff", bars: { show: true }, yaxis: 2 }, { label: "cpu core:" + _data.core + "%", data: cpucore, lines: { linewidth: 1.2}, color: "#ff0000" } ]; //redraw chart $.plot($("#flot-placeholder1"), dataset, options); //prepare update settimeout(getdata, updateinterval); } $(document).ready(function () { initdata(); dataset = [ { label: "cpu", data: cpu, lines:{fill:true, linewidth:1.2}, color: "#00ff00" }, { label: "disk:", data: disk, color: "#0044ff", bars: { show: true }, yaxis: 2 }, { label: "cpu core", data: cpucore, lines: { linewidth: 1.2}, color: "#ff0000" } ]; $.plot($("#flot-placeholder1"), dataset, options); settimeout(getdata, updateinterval); }); </script> <!-- html --> <div style="width:900px;height:600px;text-align:center;margin:10px"> <div id="flot-placeholder1" style="width:100%;height:100%;margin:0 auto"></div> </div> </asp:content>
default.asp.cs
using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; using system.web.ui.datavisualization.charting; public partial class _default : page { protected void page_load(object sender, eventargs e) { page.controls.clear(); random rnd = new random(); int cpuloading = rnd.next(0, 100); int cpucore = cpuloading - 30 < 0 ? 0 : rnd.next(0, cpuloading - 30); int disk = rnd.next(56, 1024); response.write("{\"cpu\":" + cpuloading + ", \"core\":" + cpucore + ", \"disk\":" + disk + "}"); } }
c# jquery asp.net ajax flot
Comments
Post a Comment