Data Visualization - Time Series: Line / Area Graph : UI Builder not working

Hari1
Mega Sage

Hi,

I am trying to create a Line / Area Graph using data visualization in UI Builder. I am not able to see any data when i run the page. I see the data to be blank.

Hari1_0-1714987927946.png

Below is the script:

 

Data source:

var data = [{
        "isDatabaseView": false,
        "allowRealTime": true,
        "sourceType": "table",
        "label": {
            "message": "LABEL OF YOUR DV" // Proper label
        },
        "tableOrViewName": "incident", // Table name
        "filterQuery": "cmdb_ci.ref_cmdb_ci_business_app.u_product.name=" + api.data.product_gr_1.output.name + "^sys_created_onONThis year@javascript:gs.beginningOfThisYear()@javascript:gs.endOfThisYear()", //you can bind the state values here  
        "id": "DVID" //proper ID name
    }];
    return data;

 

Metric:

var metric = [{
        "dataSource": "DVID", // from data source
        "id": "METRICID", // proper id
        "aggregateFunction": "COUNT",
        "aggregateField": "",
        "numberFormat": {
            "customFormat": false
        },
        "axisId": "primary"
    }];
    return metric;

 

 Trend by:

var trend = {
      "trendByFrequency" : "month",
            "trendByMinuteInterval" : null,
            "trendByFields" : [ {
              "field" : "sys_created_on", //trend on which field
              "metric" : "METRICID" // From metric
            } ]
    };
    return trend;

 It is not working without Group By, But i don't want the data to be set to Group By based on a field. It has to be based on the month so i have not set Group By as i have trend based on month. I am not sure what is going wrong. Can anyone please help.

 

Example of a report: I want the Data Visualization on the UI Builder to be as below.

Hari1_1-1714988257204.png

 

@Nootan Bhat, Can you please help?

 

4 REPLIES 4

Mark Manders
Mega Patron

https://www.servicenow.com/community/platform-analytics-forum/line-graph-reporting-data-visualizatio...


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Nootan Bhat
Kilo Sage

Hi @Hari1,
Try to print the below in console in data source:

 

 

api.data.product_gr_1.output.name 

 

 

If I am not wrong the data source values need to be used like:

 

 

api.data.product_gr_1.output.name.value

 

 

 because api.data.product_gr_1.output.name will return the object which holds keys value & displayValue.

Above will work for the data resource lookuprecord. But if you are using data resource  gliderecord query then the dynamic binding will be different. 

NootanBhat_0-1715082073791.png

 

 

So try using this and let me know if it resolved your issue.

 

Thanks

Nootan

Hi @Nootan Bhat

I don't see it to be working. Even if i just add a simple query as below

"sys_created_onONThis year@javascript:gs.beginningOfThisYear()@javascript:gs.endOfThisYear()^state=7" it is still not working. It just gives a blank screen on the data visualization component.

 

Below is the code:

Data source:

var data = [{
        "isDatabaseView": false,
        "allowRealTime": true,
        "sourceType": "table",
        "label": {
            "message": "LABEL OF YOUR DV" // Proper label
        },
        "tableOrViewName": "incident", // Table name
        "filterQuery": "sys_created_onONThis year@javascript:gs.beginningOfThisYear()@javascript:gs.endOfThisYear()^state=7", //you can bind the state values here  
        "id": "DVID" //proper ID name
    }];
    return data;

 

Metric:

var metric = [{
        "dataSource": "DVID", // from data source
        "id": "METRICID", // proper id
        "aggregateFunction": "COUNT",
        "aggregateField": "",
        "numberFormat": {
            "customFormat": false
        },
        "axisId": "primary"
    }];
    return metric;

 

Trend By:

var trend = {
      "trendByFrequency" : "month",
            "trendByMinuteInterval" : null,
            "trendByFields" : [ {
              "field" : "sys_created_on", //trend on which field
              "metric" : "METRICID" // From metric
            } ]
    };
    return trend;

 

Can you please help?

Hi @Nootan Bhat 

Can you please help on how to get this issue resolved, The Time Series is not working even when i pass a simple query. But the same code that i have provided on the 1st or 2nd example works fine for pie, single score, etc but not for Time Series.


Can you please share the code samples that your using to achieve this?