use of com.jjoe64.graphview.GraphViewSeries.GraphViewSeriesStyle in project netxms by netxms.
the class LineChartElement method refresh.
/* (non-Javadoc)
* @see org.netxms.ui.android.main.dashboards.elements.AbstractDashboardElement#refresh()
*/
@Override
public void refresh() {
final ChartDciConfig[] items = config.getDciList();
Log.v(TAG, "refresh(): " + items.length + " items to load");
if (items.length == 0)
return;
final long endTime = System.currentTimeMillis();
final long startTime = endTime - config.getTimeRangeMillis();
graphView.setCustomLabelFormatter(new CustomLabel(Integer.parseInt(sp.getString("global.multipliers", "1")), (endTime - startTime) > 86400 * 1000));
try {
final DciData[] dciData = new DciData[items.length];
for (int i = 0; i < dciData.length; i++) {
dciData[i] = service.getSession().getCollectedData(items[i].nodeId, items[i].dciId, new Date(startTime), new Date(endTime), 0);
}
Log.v(TAG, "refresh(): data retrieved from server");
post(new Runnable() {
@Override
public void run() {
graphView.removeAllSeries();
for (int i = 0; i < dciData.length && i < Colors.DEFAULT_ITEM_COLORS.length; i++) {
DciDataRow[] dciDataRow = dciData[i].getValues();
GraphViewData[] gvData = new GraphViewData[dciDataRow.length];
for (int j = dciDataRow.length - 1, k = 0; j >= 0; j--, k++) // dciData are reversed!
gvData[k] = new GraphViewData(dciDataRow[j].getTimestamp().getTime(), dciDataRow[j].getValueAsDouble());
int color = items[i].getColorAsInt();
color = color == -1 ? Colors.DEFAULT_ITEM_COLORS[i] : swapRGB(color);
GraphViewSeries series = new GraphViewSeries(items[i].getName(), new GraphViewSeriesStyle(color | 0xFF000000, 3), gvData);
graphView.addSeries(series);
}
graphView.setViewPort(startTime, endTime - startTime + 1);
Log.v(TAG, "refresh(): " + dciData.length + " series added; viewport set to " + startTime + "/" + (endTime - startTime + 1));
if (getChildCount() == 0)
addView(graphView);
else
graphView.redrawAll();
}
});
} catch (Exception e) {
Log.e(TAG, "Exception while reading data from server", e);
}
}
Aggregations