This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

trends from an xml file
#9
(16.11.2020, 08:31)admin Wrote: Here's an example that can be used as a starting point.
It should be modified to fetch the data remotely. It already converts CSV into correct data format for the graph library.
Code:
$(function() {
  var csv = `11-05-20 16:01:06;0,51
11-05-20 16:01:17;0,44
11-05-20 16:01:29;0,48
11-05-20 16:01:40;0,48
11-05-20 16:01:52;0,53
11-05-20 16:02:03;0,48
11-05-20 16:02:15;0,45
11-05-20 16:02:26;0,49
11-05-20 16:02:38;0,47
11-05-20 16:02:49;0,47`;

  var data = [];
  // convert CSV to correct data format
  $.each(csv.split('\n'), function(_, line) {
    var items = line.split(';')
      , d = items[0].replace(/(\d+)\-(\d+)\-(\d+) (.*)/, '20$3-$2-$1 $4')
      , n = items[1].replace(',', '.');
   
    data.push([
      new Date(d),
      Number(n)
    ]);
  });
 
  // create element for graph display, add to plan #1
  var el = $('<div></div>').css({
    position: 'absolute',
    width: 500,
    height: 300,
    left: 250,
    top: 380   
  }).appendTo('#plan-1').get(0);
 
  // create graph instance
  var graph = new Dygraph(el, data, {
    labels: [ '', 'My data' ],
    xAxisLabelWidth: 60
  });
});

graph should only be created once, to update it with new data use this:
Code:
graph.updateOptions({ file: data });

Hello Admin
Is it possible to use this way to show values from object logs as trend/curve?
Best Regards,
Reply


Messages In This Thread
trends from an xml file - by SigmaTec - 11.11.2020, 17:29
RE: trends from an xml file - by admin - 12.11.2020, 07:21
RE: trends from an xml file - by SigmaTec - 15.11.2020, 05:34
RE: trends from an xml file - by admin - 16.11.2020, 08:00
RE: trends from an xml file - by SigmaTec - 16.11.2020, 08:13
RE: trends from an xml file - by admin - 16.11.2020, 08:31
RE: trends from an xml file - by khalil - 04.02.2021, 13:37
RE: trends from an xml file - by SigmaTec - 16.11.2020, 10:58
RE: trends from an xml file - by admin - 04.02.2021, 16:21
RE: trends from an xml file - by khalil - 04.02.2021, 17:40

Forum Jump: