2013-06-20 213 views
6

當我執行的代碼波紋管,並添加mySimpleXYPlot.getGraphWidget().getBorderPaint().setColor(Color.WHITE);androidPlot黑色邊框

應用程序崩潰時我啓動我的裝置上。

我想要完成的是擺脫整個圖形周圍的黑色邊框。它位於圖表的頂部,左側和底部約2釐米厚。有什麼辦法可以擺脫這個黑色邊框嗎?

public class MainActivity extends Activity { 

private XYPlot mySimpleXYPlot; 

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

// Create a couple arrays of y-values to plot: 
    Number[] days = { 1 , 2 , 3 , 4 , 5 , 6 , 7 }; 
    Number[] values = { 380, 1433, 1965, 3200, 3651, 3215, 3217 }; 

    // initialize our XYPlot reference: 
    mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot); 
    mySimpleXYPlot.getBackgroundPaint().setColor(Color.WHITE); 
    mySimpleXYPlot.setBorderStyle(XYPlot.BorderStyle.NONE, null, null); 
    mySimpleXYPlot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE); 
    mySimpleXYPlot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE); 



    // Domain 
    mySimpleXYPlot.getGraphWidget().setDomainLabelPaint(null); 
    mySimpleXYPlot.getGraphWidget().setDomainOriginLinePaint(null); 
    mySimpleXYPlot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, days.length);  
    mySimpleXYPlot.setDomainValueFormat(new DecimalFormat("0")); 


    //Range 
    mySimpleXYPlot.getGraphWidget().setRangeOriginLinePaint(null); 
    mySimpleXYPlot.setRangeStep(XYStepMode.SUBDIVIDE, values.length); 
    mySimpleXYPlot.setRangeValueFormat(new DecimalFormat("0")); 


    //Remove legend 
    mySimpleXYPlot.getLayoutManager().remove(mySimpleXYPlot.getLegendWidget()); 
    mySimpleXYPlot.getLayoutManager().remove(mySimpleXYPlot.getDomainLabelWidget()); 
    mySimpleXYPlot.getLayoutManager().remove(mySimpleXYPlot.getRangeLabelWidget()); 
    mySimpleXYPlot.getLayoutManager().remove(mySimpleXYPlot.getTitleWidget()); 

    // Turn the above arrays into XYSeries': 
    XYSeries series1 = new SimpleXYSeries(
      Arrays.asList(days),   
      Arrays.asList(values), 
      "Series1");        // Set the display title of the series 

    // Create a formatter to use for drawing a series using LineAndPointRenderer: 
    LineAndPointFormatter series1Format = new LineAndPointFormatter(
      Color.rgb(0, 200, 0),     // line color 
      Color.rgb(0, 100, 0),     // point color 
      Color.CYAN);       // fill color 

// setup our line fill paint to be a slightly transparent gradient: 
    Paint lineFill = new Paint(); 
    lineFill.setAlpha(200); 
    lineFill.setShader(new LinearGradient(0, 0, 0, 250, Color.WHITE, Color.GREEN, Shader.TileMode.MIRROR)); 

    series1Format.setFillPaint(lineFill); 

    // add a new series' to the xyplot: 
    mySimpleXYPlot.addSeries(series1, series1Format); 

    // by default, AndroidPlot displays developer guides to aid in laying out your plot. 
    // To get rid of them call disableAllMarkup(): 
    mySimpleXYPlot.disableAllMarkup(); 
} 

} 

回答

11

如果您想擺脫圖形背後的所有顏色,您將需要以下三種方法。每一個都擺脫了不同的部分。

//This gets rid of the gray grid 
mySimpleXYPlot.getGraphWidget().getGridBackgroundPaint().setColor(Color.TRANSPARENT); 

//This gets rid of the black border (up to the graph) there is no black border around the labels 
mysimpleXYPlot.getBackgroundPaint().setColor(Color.TRANSPARENT); 

//This gets rid of the black behind the graph 
mySimpleXYPlot.getGraphWidget().getBackgroundPaint().setColor(Color.TRANSPARENT); 

//With a new release of AndroidPlot you have to also set the border paint 
plot.getBorderPaint().setColor(Color.TRANSPARENT); 

希望這會有所幫助。

+4

FWIW我必須調用'mXYPlot.setPlotMargin {Left,Right,Top,Bottom}(0);'來隱藏所有的邊框。 – Diederik

+1

@Diederik,我想我愛你。 – Joakim

3

邊界線可以通過這種方法隱藏:

plot.setBorderPaint(null); 
plot.setPlotMargins(0, 0, 0, 0); 
0

我能弄清楚如何解決與此信息的圖形,但我不得不把信息從幾個這些職位的齊心協力。似乎有4個不同的背景區域: *網格(和軸標籤) *圍繞圖的 *邊界*區域。 plot.getBackgroundPaint().setColor(background_color);

  • : *各地使用 plot.getGraphWidget().getBackgroundPaint().setColor(background_color);

  • 一輪電網區域邊界

    1. 的背景色電網和範圍/域標籤設置保證金可以通過獲取設置

      這仍然留下圍繞圖形繪製的邊框。你可以擺脫邊框: plot.setBorderPaint(null);

    或設置背景顏色

    plot.getBorderPaint().setColor(background_color);

  • 這使得周圍的整個情節的空白。這可以通過使用 plot.setPlotMargins(0, 0, 0, 0);
  • 應該有改變顏色的保證金,而不是僅僅刪除它,但沒有刻意去找出答案的方式去除。