private void updatePlot(SeriesSize seriesSize) { // Remove all current series from each plot plot.clear(); // Setup our Series with the selected number of elements series1 = new SimpleXYSeries( Arrays.asList(series1Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Us"); series2 = new SimpleXYSeries( Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Them"); plot.setDomainBoundaries(-1, series1.size(), BoundaryMode.FIXED); plot.setRangeUpperBoundary( SeriesUtils.minMax(series1, series2).getMaxY().doubleValue() + 1, BoundaryMode.FIXED); if (seriesSize != null) { switch (seriesSize) { case TEN: plot.setDomainStep(StepMode.INCREMENT_BY_VAL, 2); break; case TWENTY: plot.setDomainStep(StepMode.INCREMENT_BY_VAL, 4); break; case SIXTY: plot.setDomainStep(StepMode.INCREMENT_BY_VAL, 6); break; } } // add a new series' to the xyplot: if (series1CheckBox.isChecked()) plot.addSeries(series1, formatter1); if (series2CheckBox.isChecked()) plot.addSeries(series2, formatter2); // Setup the BarRenderer with our selected options MyBarRenderer renderer = plot.getRenderer(MyBarRenderer.class); renderer.setBarOrientation((BarRenderer.BarOrientation) spRenderStyle.getSelectedItem()); final BarRenderer.BarGroupWidthMode barGroupWidthMode = (BarRenderer.BarGroupWidthMode) spWidthStyle.getSelectedItem(); renderer.setBarGroupWidth( barGroupWidthMode, barGroupWidthMode == BarRenderer.BarGroupWidthMode.FIXED_WIDTH ? sbFixedWidth.getProgress() : sbVariableWidth.getProgress()); if (BarRenderer.BarOrientation.STACKED.equals(spRenderStyle.getSelectedItem())) { plot.getInnerLimits().setMaxY(15); } else { plot.getInnerLimits().setMaxY(0); } plot.redraw(); }
/** DESCRIPTION: Sets the boundaries for the X and Y-axis based on the data values. */ private void setPlotAxisBoundaries() { // set y-axis boundaries long boundy = 25; while (maxy >= boundy) boundy *= 2; plot.setRangeBoundaries(0, (float) boundy, BoundaryMode.FIXED); // set y-axis steps double stepy = ((double) boundy) / 10; plot.setRangeStep(XYStepMode.INCREMENT_BY_VAL, stepy); plot.setTicksPerRangeLabel(2); // set x-axis boundaries lowerboundx = minx - 1; upperboundx = maxx + 1; plot.setDomainBoundaries(lowerboundx, upperboundx, BoundaryMode.FIXED); // set x-axis steps plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 1); plot.setTicksPerDomainLabel(1); // determine the number of months being plotted long months = maxx - minx + 1; // adjust bar thickness based on number of months being plotted BarRenderer<?> barRenderer = (BarRenderer<?>) plot.getRenderer(BarRenderer.class); if (barRenderer != null) { Display display = activity.getWindowManager().getDefaultDisplay(); float displayWidth = Utilities.convertPixelsToDp(display.getWidth()); float plotWidth = displayWidth * 0.75f; float barWidth = plotWidth / months; barRenderer.setBarWidth(barWidth); } // adjust label size based on number of months being plotted xlabels.setAbbreviate(months > 6); }