Dan
Dan

Reputation: 3

How to expand graph area to use marked up area Androidplot

I am using AndroidPlot so far to create a bode plot and so far the graph looks good. Below is the graph:

Marked Up Graph

I am now trying to expand the graph area and remove all the unwanted spaces around it. I have tried: How do I remove all space around a chart in AndroidPlot?

http://androidplot.com/docs/borders-margins-and-padding/

They don't seem to do the trick. I might be missing a puzzle piece or two. Below is the code fragment:

/**
     * AndroidPlot
     */
    // Change Magnitude Plot Display
    XYPlot mChart = (XYPlot) mView.findViewById(R.id.plot_magnitude);
    Widget magGraphWidget = mChart.getGraphWidget();

    // get a handle to the layout manager:
    LayoutManager magLayoutManager = mChart.getLayoutManager();
    magLayoutManager.remove(mChart.getLegendWidget());
    magLayoutManager.remove(mChart.getDomainLabelWidget());

    XYSeries magnitudeSeries = new SimpleXYSeries(Arrays.asList(logFreqs), Arrays.asList(magImp), "Magnitude");

    // create formatters to use for drawing a series using LineAndPointRenderer
    // and configure them from xml:
    LineAndPointFormatter magnitudeSeriesFormat = new LineAndPointFormatter(
            Color.rgb(0, 0, 0), Color.rgb(50, 180, 50), null, null
    );


    // just for fun, add some smoothing to the lines:
    // see: http://androidplot.com/smooth-curves-and-androidplot/
    magnitudeSeriesFormat.setInterpolationParams(new CatmullRomInterpolator.Params(10, CatmullRomInterpolator.Type.Centripetal));

    // add a new series' to the xyplot:
    mChart.addSeries(magnitudeSeries, magnitudeSeriesFormat);

    // rotate domain labels 45 degrees to make them more compact horizontally:
    mChart.getGraphWidget().setDomainLabelOrientation(-45);

    // FILL mode with values of 0 means fill 100% of container:
    mChart.setPlotMargins(0, 0, 0, 0);
    mChart.setPlotPadding(0, 0, 0, 0);
    mChart.getGraphWidget().setMarginTop(2);
    mChart.getGraphWidget().setMarginRight(2);
    mChart.getGraphWidget().setMarginLeft(2);
    mChart.getGraphWidget().setMarginBottom(2);
    mChart.setBorderPaint(null);
    mChart.setMarkupEnabled(true);
    magGraphWidget.setBackgroundPaint(null);
    magGraphWidget.setSize(new Size(0, SizeLayoutType.FILL, 0, SizeLayoutType.FILL));
    magGraphWidget.position(-0.5f, XLayoutStyle.ABSOLUTE_FROM_LEFT, -0.5f, YLayoutStyle.ABSOLUTE_FROM_TOP); //, AnchorPosition.CENTER);

    mChart.redraw();  //update chart

Here is the XML:

<FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <com.androidplot.xy.XYPlot
                    android:id="@+id/plot_magnitude"
                    style="@style/APDefacto.Light"
                    android:layout_width="fill_parent"
                    android:layout_height="200dp"
                    ap:label="Bode Plot"
                    ap:rangeLabel="Magnitude (ohm)"
                    ap:labelTextSize="@dimen/title_font_size"
                    ap:paddingBottom="0dp"
                    android:paddingEnd="0dp"
                    ap:paddingLeft="0dp"
                    ap:paddingRight="0dp"
                    ap:paddingTop="0dp"
                    android:paddingStart="0dp"
                    android:padding="0dp"
                    android:layout_margin="0dp"
                    android:layout_marginBottom="0dp"
                    android:layout_marginEnd="0dp"
                    android:layout_marginLeft="0dp"
                    android:layout_marginRight="0dp"
                    android:layout_marginStart="0dp"
                    android:layout_marginTop="0dp"

                    />


            </FrameLayout>

If someone can give me a hand. Thanks in advance.

Upvotes: 0

Views: 163

Answers (1)

Nick
Nick

Reputation: 8317

Going by the image, it looks like it's the graph margin you're trying to remove. Try adding this to your plot XML:

ap:graphMarginLeft="0dp"
ap:graphMarginRight="0dp"
ap:graphMarginTop="0dp"
ap:graphMarginBottom="0dp"

Upvotes: 2

Related Questions