Search in sources :

Example 1 with GraphViewSeriesStyle

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);
    }
}
Also used : CustomLabel(org.netxms.ui.android.helpers.CustomLabel) ChartDciConfig(org.netxms.ui.android.main.activities.helpers.ChartDciConfig) DciData(org.netxms.client.datacollection.DciData) Date(java.util.Date) GraphViewSeries(com.jjoe64.graphview.GraphViewSeries) GraphViewSeriesStyle(com.jjoe64.graphview.GraphViewSeries.GraphViewSeriesStyle) GraphViewData(com.jjoe64.graphview.GraphView.GraphViewData)

Aggregations

GraphViewData (com.jjoe64.graphview.GraphView.GraphViewData)1 GraphViewSeries (com.jjoe64.graphview.GraphViewSeries)1 GraphViewSeriesStyle (com.jjoe64.graphview.GraphViewSeries.GraphViewSeriesStyle)1 Date (java.util.Date)1 DciData (org.netxms.client.datacollection.DciData)1 CustomLabel (org.netxms.ui.android.helpers.CustomLabel)1 ChartDciConfig (org.netxms.ui.android.main.activities.helpers.ChartDciConfig)1