Have a GraphWidget fill the entire View in AndroidPlot

孤街醉人 提交于 2019-12-11 10:47:21

问题


Is there a way to have the graph of an AndroidPlot XYPlot fill the entire view without padding?

I am specifically talking about the space on the left side that I marked red in the image:

My goal is to overlay the graph over an image and have it flush with the parent views borders. I haved removed all the labels in my subclass of XYPlot, by setting their Paint to null, the space they would take up remains though.

Here is how I set up the plot:

public void setup() {
    this.setBackgroundPaint(null);
    setPlotMarginLeft(0);

    setRangeBoundaries(-2, 2, BoundaryMode.FIXED);
    setDomainBoundaries(0, HISTORY_SIZE, BoundaryMode.FIXED);


    XYGraphWidget g = getGraphWidget();

    g.setDomainLabelPaint(null);
    g.setRangeLabelPaint(null);
    g.setDomainOriginLabelPaint(null);
    g.setRangeOriginLabelPaint(null);
    g.setGridBackgroundPaint(null);
    g.setGridPaddingLeft(0);
    g.setGridPaddingRight(0);
    g.setMarginLeft(0);
    g.setBackgroundPaint(null);
    g.position(-0.5f, XLayoutStyle.RELATIVE_TO_RIGHT, 
            -0.5f, YLayoutStyle.RELATIVE_TO_BOTTOM,
            AnchorPosition.CENTER);
    g.setSize(new SizeMetrics(
            0, SizeLayoutType.FILL,
            0, SizeLayoutType.FILL));

    LayoutManager l = getLayoutManager();
    l.remove(this.getDomainLabelWidget());
    l.remove(this.getRangeLabelWidget());
    l.remove(getLegendWidget());

    mSeries = new SimpleXYSeries("Azimuth");
    mSeries.useImplicitXVals();
    addSeries(mSeries, new LineAndPointFormatter(Color.BLACK, null, null, null));

}

回答1:


Got it, here is the code I am using to set up a Plot without any margins, padding or labels:

    XYGraphWidget g = getGraphWidget();

    g.setDomainLabelPaint(null);
    g.setRangeLabelPaint(null);
    g.setDomainOriginLabelPaint(null);
    g.setRangeOriginLabelPaint(null);
    g.setGridBackgroundPaint(null);
    g.setGridPaddingLeft(0);
    g.setGridPaddingRight(0);
    g.setMarginLeft(0);
    g.setBackgroundPaint(null);
    g.position(-0.5f, XLayoutStyle.RELATIVE_TO_RIGHT, 
            -0.5f, YLayoutStyle.RELATIVE_TO_BOTTOM,
            AnchorPosition.CENTER);
    g.setSize(new SizeMetrics(
            0, SizeLayoutType.FILL,
            0, SizeLayoutType.FILL));

    LayoutManager l = getLayoutManager();
    l.remove(this.getDomainLabelWidget());
    l.remove(this.getRangeLabelWidget());
    l.remove(getLegendWidget());

    g.setRangeLabelWidth(0);
    g.setDomainLabelWidth(0);
    g.setPadding(0, 0, 0, 0);
    g.setMargins(0, 0, 0, 0);
    g.setGridPadding(0, 0, 0, 0);
    setPlotMargins(0, 0, 0, 0);
    setPlotPadding(0, 0, 0, 0);


来源:https://stackoverflow.com/questions/19695697/have-a-graphwidget-fill-the-entire-view-in-androidplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!