I'm using groovy script to connect to mongodb. In SQL I can see mentioning we're mentioning x and y axis in the graph configuration itself.
I'm not sure how to create graphs when we're using groovy script with mongo db. Any simple example would help. Thanks in advance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It should be the same as when you're using sql. Mostly, you have to provide certain values in certain columns so you would do the same for the groovy results. So for example for a pie chart, you'll return a list of maps and each map would have 2 columns one with the category and one with the value.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here's an example with an sql source. The important part is constructing the map.
importgroovy.sql.Sqlimportart.connectionpool.DbConnectionsdefconn=nulldefsql=nullList<Map<String,Object>>result=newArrayList<>()try{conn=DbConnections.getConnection("test")sql=newSql(conn)sql.query('SELECT description, value from testdata'){resultSet->defmd=resultSet.getMetaData()defcolumnCount=md.getColumnCount()while(resultSet.next()){Map<String,Object>map=newLinkedHashMap<>()for(inti=1;i<=columnCount;i++){defcolumnName=md.getColumnLabel(i)defvalue=resultSet.getObject(i)map.put(columnName,value)}result.add(map)}}}finally{if(conn!=null){try{conn.close();}catch(IOExceptione){}}if(sql!=null){try{sql.close();}catch(IOExceptione){}}}returnresult
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm using groovy script to connect to mongodb. In SQL I can see mentioning we're mentioning x and y axis in the graph configuration itself.
I'm not sure how to create graphs when we're using groovy script with mongo db. Any simple example would help. Thanks in advance.
It should be the same as when you're using sql. Mostly, you have to provide certain values in certain columns so you would do the same for the groovy results. So for example for a pie chart, you'll return a list of maps and each map would have 2 columns one with the category and one with the value.
Here's an example with an sql source. The important part is constructing the map.