Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

 

...

Image AddedImage Added

Description: This component can show up to 7 points.  To view the data, a query tag must be put on the component with the value set to the desired query.  An example would be 

...

or readAll((equipRef==$id) and ((navName=="Damper") or(navName=="AirFlow")))

Download

...

historyDatePickerChartRange.f5m

Make Your Own

Ractive

Image Modified Image Modified Image Modified Image Modified



  • Make sure AM|Charts is dragged out into the workspace as well as moment.min.js
  • Next drag out Ractive and add a marker tag called historyDatePickerChart
  • Add a string tag to the component called query with the value set to the desired query (Note the point must have a his but you do not need to add .hisRead)
  • Open up the Ractive Editor under properties
  • Copy and paste the code below into the corresponding tabs

Template

Code Block
titleTemplate Code
linenumberstrue
collapsetrue
<div class="s-box">
    <div class="buttonBar">
        <div class="s-button s-selected" id="day" on-click="day">Today</div>
        <div class="s-button" id="week" on-click="week">This Week</div>
        <div class="s-button" id="month" on-click="month">This Month</div>
        <div class="s-button" id="datePicker" on-click="datePicker">{{#if myStart==myEnd}}{{myStart}}{{else}}{{myStart}}-{{myEnd}}{{/if}}</div>
    </div>     <div<div class="s-button" id="amChartPointdatePickerStart" styleon-click="width:100%; height:100%;"></div>
</div>

Model

Code Block
titleModel Code
linenumberstrue
collapsetrue
{datePickerStart">{{startPick}}</div>
    data:     {
        myStart: "Date Picker",<div class="s-button" id="datePickerEnd" on-click="datePickerEnd">{{endPick}}</div>
    </div>
    myEnd: "Date Picker"
    }
}

...

<div id="amChartPoint" style="width:100%; height:100%;"></div>
</div>


Model

Code Block
titleStyle Model Code
linenumberstrue
collapsetrue
.s-box{
    paddingdata:
  10px;  {
  border-radius: 5px;     widthmyStart: 100%;
"Date Picker",
   height: 100%;     displaymyEnd: flex;
"Date Picker",
   flex-direction: column;     flexstartPick: 1"Start",
1 auto; } .buttonBar{     widthendPick:100%; "End"
   height:35px;
 }
}

Style

Code Block
titleStyle Code
linenumberstrue
collapsetrue
.s-box{
    padding: 10px;
    border-radius: 5px;
    background-colorwidth: #4f7ab3100%;
    displayheight: flex100%;
    flex-directiondisplay: rowflex;
    justifyflex-contentdirection: centercolumn;
    align-items: centerflex: 1 1 auto;
}
.s-buttonbuttonBar{
    colorwidth:#fff100%;
    border-radius: 5pxheight:35px;
    width:100%;
    heightborder-radius: 100%5px;
    fontbackground-weightcolor: bold;
    padding: 10px 15px 10px 15px;
    #4f7ab3;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
}
.s-button{
    cursorcolor:#fff;
  pointer; } .s-selected{border-radius: 5px;
    background-colorwidth:100%;
#7093c1;
}

Init

Code Block
titleInit Code
linenumberstrue
collapsetrue
this.ractive.fire("obtainData");
var template  = this;
var model     = this.ractive;

var tpoint = model.queryAll("targetPoint");
if(tpoint.length > 0) tpoint = tpoint[0].pointId;
else tpoint = "undefined";

var query = this.query.replace(/\$id/g, tpoint);
var dataQuery = query+'.hisRead(today)';

function updateChart(newQuery, buttonInd){
    var test = template.view.querySelector("#amChartPoint");
    var buttonIds = [
        template.view.querySelector("#day"),
        template.view.querySelector("#week"),
        template.view.querySelector("#month"),
        template.view.querySelector("#datePicker")
    ];
    
    buttonIds.forEach(function(itm){ itm.style.backgroundColor = "#4f7ab3"; });
    buttonIds[buttonInd].style.backgroundColor = "#7093c1";
    
    setTimeout(function() {
        finstack.eval(newQuery, function(event){
            var cols = [];    height: 100%;
    font-weight: bold;
    padding: 10px 15px 10px 15px;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}
.s-selected{
    background-color: #7093c1;
}

Init

Code Block
titleInit Code
linenumberstrue
collapsetrue
this.ractive.fire("obtainData");
var template  = this;
var model     = this.ractive;
var startRange = "";
var endRange = "";
var tpoint = model.queryAll("targetPoint");
if(tpoint.length > 0) tpoint = tpoint[0].pointId;
else tpoint = "undefined";

var query = this.query.replace(/\$id/g, tpoint);
var dataQuery = query+'.hisRead(today)';

function clearTabs(item){
    model.set('myStart', "Date Picker");
    model.set('myEnd', "Date Picker");
    model.set('startPick', "Start");
    model.set('endPick', "End");
}

function updateChart(newQuery, buttonInd){
    var test = template.view.querySelector("#amChartPoint");
    var buttonIds = [
            event.result.columns.forEach(function(itm){template.view.querySelector("#day"),
            template.view.querySelector("#week"),
   var   t = /v\d+/.exec(itm.name); template.view.querySelector("#month"),
        template.view.querySelector("#datePicker"),
       if(t !== null && t[0] == t.input){ template.view.querySelector("#datePickerStart"),
           template.view.querySelector("#datePickerEnd")
    ];
   if(itm.metadata) cols.push({dis:
itm.metadata.idDis || itm.metadata.dis || itm.metadata.id, col: itm.name, unit: itm.metadata.unit || null, equipRefDis: itm.metadata.equipRefDisbuttonIds.forEach(function(itm){ itm.style.backgroundColor = "#4f7ab3"; });
    buttonIds[buttonInd].style.backgroundColor = "#7093c1";
    
        else cols.push({dis: itm.name, col: itm.name});setTimeout(function() {
        finstack.eval(newQuery, function(event){
         }   var cols = [];
      });      event.result.columns.forEach(function(itm){
                   var grphst = []/v\d+/.exec(itm.name);
            var cou = 0; if(t !== null && t[0] == t.input){
     cols.forEach(function(itm){                 grphsif(itm.metadata) cols.push({dis: itm.metadata.idDis || itm.metadata.dis || itm.metadata.id, col: itm.name, unit: itm.metadata.unit || null, equipRefDis: itm.metadata.equipRefDis});
                "id": "g"+cou,
    else cols.push({dis: itm.name, col: itm.name});
                }
  "balloonText": ""+itm.equipRefDis+": [["+itm.col+"]] "+itm.unit+"",          });
            
   "lineThickness": 2,        var grphs = [];
         "title": itm.dis,  var cou = 0;
            cols.forEach(function(itm){
    "unit" : itm.unit,          grphs.push({
          "valueField": itm.col,         "id": "g"+cou,
          "fillAlphas": 0.2 //Area        "balloonText": ""+itm.equipRefDis+": [["+itm.col+"]] "+itm.unit+"",
     });               "lineThickness": 2,
cou++;             });       "title": itm.dis,
                  var  myData"unit" =: event.result.toObj();itm.unit,
             var chartData =[];     "valueField": itm.col,
      var myData2 = [];           "fillAlphas": 0.2 //Area
            myData.forEach(function(itm){    });
            myData2.push({    cou++;
            });
   "ts": itm.ts,        
            "tsOffset": itm.tsOffset,
 var myData = event.result.toObj();
            var chartData =[];
   "tsTimezone": itm.tsTimezone,        var myData2 = [];
         "v0": itm.v0 || 0,
            myData.forEach(function(itm){
       "v1": itm.v1 || 0,      myData2.push({
                    "v2ts": itm.v2 || 0ts,
                    "v3tsOffset": itm.v3 || 0tsOffset,
                    "v4tsTimezone": itm.v4 || 0tsTimezone,
                    "v5v0": itm.v5v0 || 0,
                    "v6v1": itm.v6v1 || 0,
                    "v7v2": itm.v7v2 || 0,
                });    "v3": itm.v3 || 0,
     });               "v4": itm.v4 || 0,
        myData2.forEach(function(itm){            "v5": itm.v5    chartData.push({|| 0,
                    "tsv6": itm.tsv6 || 0,
                    "tsOffsetv7": itm.tsOffset,v7 || 0
                });
 "tsTimezone": itm.tsTimezone,          });
          "v0": itm.v0.toFixed(1) ||
null,              myData2.forEach(function(itm){
               "v1": itmchartData.v1.toFixed(1) || null,push({
                     "v2ts": itm.v2.toFixed(1) || nullts,
                    "v3tsOffset": itm.v3.toFixed(1) || nulltsOffset,
                    "v4tsTimezone": itm.v4.toFixed(1) || nulltsTimezone,
                    "v5v0": itm.v5v0.toFixed(1) || null,
                    "v6v1": itm.v6v1.toFixed(1) || null,
                    "v7v2": itm.v7v2.toFixed(1) || null,
                     });"v3": itm.v3.toFixed(1) || null,
                });    "v4": itm.v4.toFixed(1) || null,
                  var chart = AmCharts.makeChart(test, {"v5": itm.v5.toFixed(1) || null,
                    "typev6": "serial", itm.v6.toFixed(1) || null,
                    "themev7": "light", itm.v7.toFixed(1) || null
                "marginRight": 80,});
            });
    "dataProvider": chartData,       
         "valueAxes": [{  var chart = AmCharts.makeChart(test, {
              "axisAlpha  "type": 0.1 "serial",
                 }]"theme": "light",
                "graphsmarginRight": grphs80,
                "zoomOutButtonRollOverAlphadataProvider": 0.15chartData,
                "chartCursorvalueAxes": [{
                    "categoryBalloonDateFormataxisAlpha": "MMMM D L:NN A",0.1
                }],
                "cursorPositiongraphs": "mouse"grphs,
                    "showNextAvailablezoomOutButtonRollOverAlpha": true0.15,
                },
                "legend"chartCursor": {
                    "equalWidths": truecategoryBalloonDateFormat": "MMMM D L:NN A",
                    "positioncursorPosition": "topmouse",
                    "valueAlignshowNextAvailable": "left",true
                },
   "valueWidth": 100            "legend": {
   },                 "autoMarginOffsetequalWidths": 5true,
                    "columnWidthposition": 1"top",
                    "categoryFieldvalueAlign": "tsleft",
                    "categoryAxisvalueWidth": { 100
                },
                "parseDatesautoMarginOffset": true5,
                "columnWidth": 1,
  "minPeriod": "mm",             "categoryField": "ts",
      "dateFormats":[          "categoryAxis": {
             {       "parseDates": true,
                    "periodminPeriod": "fffmm",
                    "dateFormats":[
       "format":"L:NN:SS A"
                        },                         {
                            "period":"ssfff",
                            "format":"L:NN:SS A"
                        },
                        {
                            "period":"mmss",
                            "format":"L:NN:SS A"
                        },
                        {
                            "period":"hhmm",
                            "format":"L:NN A"
                        },
                        {
                            "period":"DDhh",
                            "format":"MMML:NN DDA"
                        },
                        {
                            "period":"WWDD",
                            "format":"MMM DD"
                        },
                        {
                            "period":"MMWW",
                            "format":"MMM DD"
                        },
                        {
                            "period":"YYYYMM",
                            "format":"YYYYMMM"
                    }]    },
             },           {
     "chartScrollbar": { 	                "enabled": true    "period":"YYYY",
            },                 "exportformat":"YYYY"
{                     "enabled": true}]
                 },
            });    "chartScrollbar": {
 	                   chart.addListener("rendered", zoomChart);"enabled": true,
             zoomChart();   },
         function zoomChart() {      "export": {
                    chart.zoomToIndexes(chart.dataProvider.length - 40, chart.dataProvider.length - 1);"enabled": true
                },
            });
         },  200); }
this.ractive.on("day", function(event) {     updateChart(dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead(today)'), 0);
});
this.ractive.on("week", function(event     chart.addListener("rendered", zoomChart);
            zoomChart();
            function zoomChart() {
    updateChart(dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead(thisWeek)'), 1);
});
this.ractive.on("month", function(event) {
    updateChart(            chart.zoomToIndexes(chart.dataProvider.length - 40, chart.dataProvider.length - 1);
            }
        });
    }, 200);
}
this.ractive.on("day", function(event) {
    clearTabs(true);
    updateChart(dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead(today)'), 0);
});
this.ractive.on("week", function(event) {
    clearTabs(true);
    updateChart(dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead(thisWeek)'), 1);
});
this.ractive.on("month", function(event) {
    clearTabs(true);
    updateChart(dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead(thisMonth)'), 2);
});
this.ractive.on("datePicker", function(event) {
    clearTabs(true);
    top.app.ShowCalendar(null,function(data){
        var start = moment(data.range.start).format("YYYY-MM-DD");
        var end   = moment(data.range.end).format("YYYY-MM-DD");
        var dateStringStart = start;
        var startDate = new moment(dateStringStart).format('MM/DD/YYYY');
        var dateStringEnd = end;
        var endDate = new moment(dateStringEnd).format('MM/DD/YYYY');
        model.set('myStart', startDate);
        model.set('myEnd', endDate);
        var newQuery = "";
        if(start == end) newQuery= dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead('+start+')');
        else newQuery= dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead('+start+'..'+end+')');
        updateChart(newQuery, 3);
    },
    {periods:true});
});
this.ractive.on("datePickerStart", function(event) {
        clearTabs(true);
     top.app.ShowCalendar(null,function(data){
        startRange = moment(data.range.start).format("YYYY-MM-DD");
        var dateStringStart = startRange;
        var startDate = new moment(dateStringStart).format('MM/DD/YYYY');
        model.set('startPick', startDate);
        var newQuery = "";
        // newQuery = dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead(thisMonth)'), 2);
});
this.ractive.on("datePicker", function(event) {
    top.app.ShowCalendar(null,function(data){g,'.hisRead('+start+')');
        var start = moment(data.range.start).format("YYYY-MM-DD"updateChart("", 4);
    });
});
this.ractive.on("datePickerEnd", function(event) var{
end   = moment(data.range.end).format("YYYY-MM-DDmodel.set('myStart', "Date Picker");
    model.set('myEnd', "Date Picker");
 var dateStringStart = start;
 top.app.ShowCalendar(null,function(data){
       var startDateendRange = new moment(dateStringStartdata.range.end).format('"YYYY-MM/-DD/YYYY'");
        var dateStringEnd = endendRange;
        var endDate = new moment(dateStringEnd).format('MM/DD/YYYY');
        
;
       var newQuery = "" model.set('endPick', endDate);
        if(start == end) newQuery= dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead('+start+')')var newQuery = "";
        else newQuery= dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead('+startstartRange+'..'+endendRange+')');
        updateChart(newQuery, 35);
    },
    {periods:true});
});


Image Modified

Program

  • Go to programs in the left menu
  • Click the plus to add a new program, and it will pull up the program editor
  • In the Program Target Filter type historyDatePickerChart
  • Click the three dots in the top right corner, and select variables
  • Click the gear that appears as you hover over "this"
  • Turn on Invokes the Function
  • Change the dropdown to Custom Event
  • In the textbox below the dropdown type obtainData
  • Click the gray Save button
  • Click the + next to Program Vars to add another variable
  • Name it point on the top line, and underneath put id==$virtualPointRef
  • Click the gray Save button
  • Copy and paste the code below into the main section and click the blue save

Code

Code Block
titleProgram Code
linenumberstrue
collapsetrue
var tpoint = queryAll("targetPoint");
if(tpoint.length > 0) tpoint = tpoint[0].pointId;
else tpoint = "undefined";

var query = this.query.replace(/\$id/g, tpoint);

this.ractive.fire("day");

...