2013-06-20 167 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);
  • 应该有改变颜色的保证金,而不是仅仅删除它,但没有刻意去找出答案的方式去除。