Search in sources :

Example 1 with XYSeries

use of org.achartengine.model.XYSeries in project AndrOBD by fr3ts0n.

the class ObdItemAdapter method addAllDataSeries.

/**
 * Add data series to all process variables
 */
protected synchronized void addAllDataSeries() {
    String pluginStr = "";
    for (IndexedProcessVar pv : (Iterable<IndexedProcessVar>) pvs.values()) {
        XYSeries series = (XYSeries) pv.get(FID_DATA_SERIES);
        if (series == null) {
            series = new XYSeries(String.valueOf(pv.get(EcuDataPv.FID_DESCRIPT)));
            pv.put(FID_DATA_SERIES, series);
            pv.addPvChangeListener(this, PvChangeEvent.PV_MODIFIED);
        }
        // assemble data items for plugin notification
        pluginStr += String.format("%s;%s;%s;%s\n", pv.get(EcuDataPv.FID_MNEMONIC), pv.get(EcuDataPv.FID_DESCRIPT), String.valueOf(pv.get(EcuDataPv.FID_VALUE)), pv.get(EcuDataPv.FID_UNITS));
    }
    // notify plugins
    if (PluginManager.pluginHandler != null) {
        PluginManager.pluginHandler.sendDataList(pluginStr);
    }
}
Also used : XYSeries(org.achartengine.model.XYSeries) IndexedProcessVar(com.fr3ts0n.pvs.IndexedProcessVar)

Example 2 with XYSeries

use of org.achartengine.model.XYSeries in project netxms by netxms.

the class BarChartElement method refresh.

/* (non-Javadoc)
	 * @see org.netxms.ui.android.main.dashboards.elements.AbstractDashboardElement#refresh()
	 */
@Override
public void refresh() {
    final ChartDciConfig[] items = config.getDciList();
    if (items.length == 0)
        return;
    try {
        final DciData[] dciData = new DciData[items.length];
        for (int i = 0; i < dciData.length; i++) {
            dciData[i] = new DciData(0, 0);
            dciData[i] = service.getSession().getCollectedData(items[i].nodeId, items[i].dciId, null, null, 1);
        }
        post(new Runnable() {

            @Override
            public void run() {
                XYMultipleSeriesDataset dataset = chart.getDataset();
                for (int i = 0; i < dciData.length; i++) {
                    dataset.removeSeries(i);
                    XYSeries series = new XYSeries(items[i].getName());
                    for (int j = 0; j < items.length; j++) {
                        series.add(j + 1, (i == j) ? dciData[i].getLastValue().getValueAsDouble() : 0);
                    }
                    dataset.addSeries(i, series);
                }
                chartView.repaint();
            }
        });
    } catch (Exception e) {
        Log.e(TAG, "Exception while reading data from server", e);
    }
}
Also used : XYSeries(org.achartengine.model.XYSeries) ChartDciConfig(org.netxms.ui.android.main.activities.helpers.ChartDciConfig) DciData(org.netxms.client.datacollection.DciData) XYMultipleSeriesDataset(org.achartengine.model.XYMultipleSeriesDataset)

Example 3 with XYSeries

use of org.achartengine.model.XYSeries in project netxms by netxms.

the class BarChartElement method buildDataset.

/**
 * @return
 */
private XYMultipleSeriesDataset buildDataset() {
    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
    ChartDciConfig[] items = config.getDciList();
    for (int i = 0; i < items.length; i++) {
        XYSeries series = new XYSeries(items[i].getName());
        for (int j = 0; j < items.length; j++) {
            series.add(j + 1, 0);
        }
        dataset.addSeries(series);
    }
    return dataset;
}
Also used : XYSeries(org.achartengine.model.XYSeries) ChartDciConfig(org.netxms.ui.android.main.activities.helpers.ChartDciConfig) XYMultipleSeriesDataset(org.achartengine.model.XYMultipleSeriesDataset)

Example 4 with XYSeries

use of org.achartengine.model.XYSeries in project Anki-Android by Ramblurr.

the class ChartBuilder method onCreate.

// public void setRenderer(int type, int row) {
// Resources res = getResources();
// XYSeriesRenderer renderer = new XYSeriesRenderer();
// if (type <= 2) {
// switch (row) {
// case 0:
// renderer.setColor(res.getColor(R.color.statistics_due_young_cards));
// break;
// case 1:
// renderer.setColor(res.getColor(R.color.statistics_due_mature_cards));
// break;
// case 2:
// // renderer.setColor(res.getColor(R.color.statistics_due_failed_cards));
// break;
// }
// } else if (type == 3) {
// switch (row) {
// case 0:
// // renderer.setColor(res.getColor(R.color.statistics_reps_new_cards));
// break;
// case 1:
// renderer.setColor(res.getColor(R.color.statistics_reps_young_cards));
// break;
// case 2:
// renderer.setColor(res.getColor(R.color.statistics_reps_mature_cards));
// break;
// }
// } else {
// renderer.setColor(res.getColor(R.color.statistics_default));
// }
// mRenderer.addSeriesRenderer(renderer);
// }
@Override
protected void onCreate(Bundle savedInstanceState) {
    // Log.i(AnkiDroidApp.TAG, "ChartBuilder.OnCreate");
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);
    restorePreferences();
    Resources res = getResources();
    Stats stats = Stats.currentStats();
    if (stats != null) {
        mSeriesList = stats.getSeriesList();
        mMeta = stats.getMetaInfo();
    } else if (savedInstanceState != null) {
        int len = savedInstanceState.getInt("seriesListLen");
        mSeriesList = new double[len][];
        for (int i = 0; i < len; i++) {
            mSeriesList[i] = (double[]) savedInstanceState.getSerializable("seriesList" + i);
        }
        mMeta = (Object[]) savedInstanceState.getSerializable("meta");
    } else {
        finish();
    }
    String title = res.getString((Integer) mMeta[1]);
    boolean backwards = (Boolean) mMeta[2];
    int[] valueLabels = (int[]) mMeta[3];
    int[] barColors = (int[]) mMeta[4];
    int[] axisTitles = (int[]) mMeta[5];
    String subTitle = (String) mMeta[6];
    if (mSeriesList == null || mSeriesList[0].length < 2) {
        // Log.i(AnkiDroidApp.TAG, "ChartBuilder - Data variable empty, closing chartbuilder");
        finish();
        return;
    }
    if (mFullScreen) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }
    View mainView = getLayoutInflater().inflate(R.layout.statistics, null);
    setContentView(mainView);
    mainView.setBackgroundColor(Color.WHITE);
    mTitle = (TextView) findViewById(R.id.statistics_title);
    if (mChartView == null) {
        if (mFullScreen) {
            mTitle.setText(title);
            mTitle.setTextColor(Color.BLACK);
        } else {
            setTitle(title);
            AnkiDroidApp.getCompat().setSubtitle(this, subTitle);
            mTitle.setVisibility(View.GONE);
        }
        for (int i = 1; i < mSeriesList.length; i++) {
            XYSeries series = new XYSeries(res.getString(valueLabels[i - 1]));
            for (int j = 0; j < mSeriesList[i].length; j++) {
                series.add(mSeriesList[0][j], mSeriesList[i][j]);
            }
            mDataset.addSeries(series);
            XYSeriesRenderer renderer = new XYSeriesRenderer();
            renderer.setColor(res.getColor(barColors[i - 1]));
            mRenderer.addSeriesRenderer(renderer);
        }
        if (mSeriesList.length == 1) {
            mRenderer.setShowLegend(false);
        }
        if (backwards) {
            mPan = new double[] { mSeriesList[0][0] - 0.5, 0.5 };
        } else {
            mPan = new double[] { -0.5, mSeriesList[0][mSeriesList[0].length - 1] + 0.5 };
        }
        mRenderer.setLegendTextSize(17);
        mRenderer.setBarSpacing(0.4);
        mRenderer.setLegendHeight(60);
        mRenderer.setAxisTitleTextSize(17);
        mRenderer.setLabelsTextSize(17);
        mRenderer.setXAxisMin(mPan[0]);
        mRenderer.setXAxisMax(mPan[1]);
        mRenderer.setYAxisMin(0);
        mRenderer.setGridColor(Color.LTGRAY);
        mRenderer.setShowGrid(true);
        mRenderer.setXTitle(res.getStringArray(R.array.due_x_axis_title)[axisTitles[0]]);
        mRenderer.setYTitle(res.getString(axisTitles[1]));
        mRenderer.setBackgroundColor(Color.WHITE);
        mRenderer.setMarginsColor(Color.WHITE);
        mRenderer.setAxesColor(Color.BLACK);
        mRenderer.setLabelsColor(Color.BLACK);
        mRenderer.setYLabelsColor(0, Color.BLACK);
        mRenderer.setYLabelsAngle(-90);
        mRenderer.setXLabelsColor(Color.BLACK);
        mRenderer.setXLabelsAlign(Align.CENTER);
        mRenderer.setYLabelsAlign(Align.CENTER);
        mRenderer.setZoomEnabled(false, false);
        mRenderer.setMargins(new int[] { 15, 48, 30, 10 });
        mRenderer.setAntialiasing(true);
        mRenderer.setPanEnabled(true, false);
        mRenderer.setPanLimits(mPan);
        mChartView = ChartFactory.getBarChartView(this, mDataset, mRenderer, BarChart.Type.STACKED);
        LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
        layout.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    } else {
        mChartView.repaint();
    }
    gestureDetector = new GestureDetector(new MyGestureDetector());
    mChartView.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            if (gestureDetector.onTouchEvent(event)) {
                return true;
            }
            return false;
        }
    });
}
Also used : XYSeries(org.achartengine.model.XYSeries) LayoutParams(android.view.ViewGroup.LayoutParams) GestureDetector(android.view.GestureDetector) View(android.view.View) GraphicalView(org.achartengine.GraphicalView) TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent) Stats(com.ichi2.libanki.Stats) XYSeriesRenderer(org.achartengine.renderer.XYSeriesRenderer) Resources(android.content.res.Resources) LinearLayout(android.widget.LinearLayout)

Example 5 with XYSeries

use of org.achartengine.model.XYSeries in project Anki-Android by Ramblurr.

the class FitZoom method apply.

/**
 * Apply the tool.
 */
public void apply() {
    if (mChart instanceof XYChart) {
        if (((XYChart) mChart).getDataset() == null) {
            return;
        }
        int scales = mRenderer.getScalesCount();
        if (mRenderer.isInitialRangeSet()) {
            for (int i = 0; i < scales; i++) {
                if (mRenderer.isInitialRangeSet(i)) {
                    mRenderer.setRange(mRenderer.getInitialRange(i), i);
                }
            }
        } else {
            XYSeries[] series = ((XYChart) mChart).getDataset().getSeries();
            double[] range = null;
            int length = series.length;
            if (length > 0) {
                for (int i = 0; i < scales; i++) {
                    range = new double[] { MathHelper.NULL_VALUE, -MathHelper.NULL_VALUE, MathHelper.NULL_VALUE, -MathHelper.NULL_VALUE };
                    for (int j = 0; j < length; j++) {
                        if (i == series[j].getScaleNumber()) {
                            range[0] = Math.min(range[0], series[j].getMinX());
                            range[1] = Math.max(range[1], series[j].getMaxX());
                            range[2] = Math.min(range[2], series[j].getMinY());
                            range[3] = Math.max(range[3], series[j].getMaxY());
                        }
                    }
                    double marginX = Math.abs(range[1] - range[0]) / 40;
                    double marginY = Math.abs(range[3] - range[2]) / 40;
                    mRenderer.setRange(new double[] { range[0] - marginX, range[1] + marginX, range[2] - marginY, range[3] + marginY }, i);
                }
            }
        }
    } else {
        DefaultRenderer renderer = ((RoundChart) mChart).getRenderer();
        renderer.setScale(renderer.getOriginalScale());
    }
}
Also used : XYSeries(org.achartengine.model.XYSeries) DefaultRenderer(org.achartengine.renderer.DefaultRenderer) XYChart(org.achartengine.chart.XYChart) RoundChart(org.achartengine.chart.RoundChart)

Aggregations

XYSeries (org.achartengine.model.XYSeries)15 XYMultipleSeriesDataset (org.achartengine.model.XYMultipleSeriesDataset)5 XYSeriesRenderer (org.achartengine.renderer.XYSeriesRenderer)4 Paint (android.graphics.Paint)3 ArrayList (java.util.ArrayList)3 Resources (android.content.res.Resources)2 Align (android.graphics.Paint.Align)2 Rect (android.graphics.Rect)2 LayoutParams (android.view.ViewGroup.LayoutParams)2 IndexedProcessVar (com.fr3ts0n.pvs.IndexedProcessVar)2 Date (java.util.Date)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 GraphicalView (org.achartengine.GraphicalView)2 RoundChart (org.achartengine.chart.RoundChart)2 XYChart (org.achartengine.chart.XYChart)2 Point (org.achartengine.model.Point)2 DefaultRenderer (org.achartengine.renderer.DefaultRenderer)2 Orientation (org.achartengine.renderer.XYMultipleSeriesRenderer.Orientation)2 ChartDciConfig (org.netxms.ui.android.main.activities.helpers.ChartDciConfig)2