首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >androidPlot黑色边框

androidPlot黑色边框
EN

Stack Overflow用户
提问于 2013-06-21 02:14:00
回答 3查看 2.9K关注 0票数 6

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

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

我想要完成的是去掉整个图周围的黑色边框。它大约有2厘米厚,位于图表的顶部、左侧和底部。有什么办法可以去掉这个黑色边框吗?

代码语言:javascript
复制
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();
}

}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-06-25 04:11:16

如果您想摆脱图形背后的所有颜色,您将需要以下三种方法。每一个都去掉了不同的部分。

代码语言:javascript
复制
//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);

希望这能有所帮助。

票数 11
EN

Stack Overflow用户

发布于 2014-02-27 12:12:18

边框线可以通过此方法隐藏:

代码语言:javascript
复制
plot.setBorderPaint(null);
plot.setPlotMargins(0, 0, 0, 0);
票数 3
EN

Stack Overflow用户

发布于 2015-03-03 02:19:15

我能够想出如何用这些信息来修复图表,但我必须将其中几个帖子的信息集中在一起。有4个不同的背景区域:*网格(和轴标签)*图形周围的区域*图形周围的边界。*边界周围的边际

网格的背景色和范围/域标签是使用plot.getGraphWidget().getBackgroundPaint().setColor(background_color);

  • The区域设置的,网格周围的区域可以通过以下方式设置:plot.getBackgroundPaint().setColor(background_color);

  • This
  1. 在图形周围绘制的边框。你可以去掉边框:plot.setBorderPaint(null);

或设置背景颜色

plot.getBorderPaint().setColor(background_color);

  1. 这会在整个绘图周围留下空白处。可以使用plot.setPlotMargins(0, 0, 0, 0);

将其删除

应该有一种方法来改变页边距的颜色,而不是简单地删除它,但没有费心弄清楚这一点。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17220821

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档