This is the beginning of how to create dashboard Charts Like this:
Chart:
Sample Code 1 :
package com.cloupia.feature.slimcea.reports;
import com.cloupia.model.cIM.ReportContext;
import com.cloupia.model.cIM.ReportNameValuePair;
import com.cloupia.model.cIM.SnapshotReport;
import com.cloupia.model.cIM.SnapshotReportCategory;
import com.cloupia.service.cIM.inframgr.SnapshotReportGeneratorIf;
import com.cloupia.service.cIM.inframgr.reportengine.ReportRegistryEntry;
public class SamplePieChartReportImpl implements SnapshotReportGeneratorIf {
@Override
public SnapshotReport getSnapshotReport(ReportRegistryEntry reportEntry, ReportContext context) throws Exception {
SnapshotReport report = new SnapshotReport(); report.setContext(context);
report.setReportName(reportEntry.getReportLabel());
report.setNumericalData(true); report.setDisplayAsPie(true);
report.setPrecision(0);
//creation of report name value pair goes
ReportNameValuePair[] rnv = new ReportNameValuePair[5];
for (int i = 0; i < rnv.length; i++) {
rnv[i] = new ReportNameValuePair("category" + i, (i+1) * 5);
}
//setting of report category goes
SnapshotReportCategory cat = new SnapshotReportCategory();
cat.setCategoryName(""); cat.setNameValuePairs(rnv);
report.setCategories(new SnapshotReportCategory[] { cat });
return report;
}
}
Sample Code 2:
package com.cloupia.feature.slimcea.reports;
import com.cloupia.feature.slimcea.constants.SlimceaConstants;
import com.cloupia.model.cIM.DynReportContext;
import com.cloupia.model.cIM.ReportContextRegistry;
import com.cloupia.model.cIM.ReportDefinition;
import com.cloupia.service.cIM.inframgr.reportengine.ContextMapRule;
import com.cloupia.service.cIM.inframgr.reports.simplified.CloupiaNonTabularReport;
public class SamplePieChartReport extends CloupiaNonTabularReport {
// Unique report name here.
private static final String NAME = "my.first.pie.chart";
private static final String LABEL = "My First Pie Chart";
//Returns implementation class
@SuppressWarnings("rawtypes")
@Override
public Class getImplementationClass() {
return SamplePieChartReportImpl.class;
}
//Returns report type for pie chart as shown below
@Override
public int getReportType() {
return ReportDefinition.REPORT_TYPE_SNAPSHOT;
}
@Override
public String getReportLabel() {
return LABEL;
}
@Override
public String getReportName() {
return NAME;
}
// Forcing this report into the Physical->Storage part of the GUI.
@Override
public int getMenuID() {
return 51;
}
//Returns report hint for pie chart as shown below
@Override
public int getReportHint() {
return ReportDefinition.REPORT_HINT_PIECHART;
}
@Override
public ContextMapRule[] getMapRules() {
DynReportContext dummyContextOneType = ReportContextRegistry.getInstance().getContextByName(SlimceaConstants.INFRA_ACCOUNT_TYPE);
ContextMapRule rule = new ContextMapRule();
rule.setContextName(dummyContextOneType.getId());
rule.setContextType(dummyContextOneType.getType());
ContextMapRule[] rules = new ContextMapRule[1];
rules[0] = rule;
return rules;
}
}
The inspiration came from:
You use API to get the historical data for the summary data.
http://172.31.234.115/app/api/rest?formatType=json&opName=userAPIGetHistoricalReport&opData={param0:”1”,param1:”Cloud-152”,param2:”TREND-NUMBER-OF-HOST-NODES-H0”,param3:”weekly”}
{"serviceResult": {"series": [{"paramName": "totalHostNodes","paramLabel": "Total Host Nodes","values": [{"timestamp": 1456287349796,"min": 7,"max": 7,"avg": 7},{"timestamp": 1456296276538,"min": 7,"max": 7,"avg": 7},{"timestamp": 1456299877654,"min": 7,"max": 7,"avg": 7},
This is corresponding following widget in UI (data might be from other report in this pic)
http://172.31.234.115/app/api/rest?formatType=json&opName=userAPIGetInstantDataReport&opData={param0:”1”,param1:”Cloud-152”,param2:”VMS-ACTIVE-VS-INACTIVE-S0”}
{"serviceResult": {"categoryAxisName": null,"valueAxisName": "Active vs Inactive","categories": [{"categoryName": "","nameValuePairs": [{"name": "Active VMs","value": "34"},{"name": "Inactive VMs","value": "5"}]}]},"serviceError": null,"serviceName": "InfraMgr","opName": "userAPIGetInstantDataReport"}
This corresponds to following widget in summary