java – androidPlot黑色边框

当我执行下面的代码添加mySimpleXYPlot.getGraphWidget().getBorderPaint().setColor(Color.WHITE);

当我在我的设备上启动它时,应用程序崩溃了.

我想要完成的是摆脱整个图形周围的黑色边框.它位于图表的顶部,左侧和底部两侧约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,// 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,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();
}

}

解决方法

如果要删除图表背后的所有颜色,则需要以下三种方法.每个都摆脱不同的部分.
//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);

希望这可以帮助.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...