3

我正在尝试使用 AndroidPlot 在主屏幕小部件中绘制图表。我知道在普通应用程序中,它使用自定义视图,并且根据我所见(Android:AppWidget with custom view not working),解决方法是将其渲染为imageView.

现在我已经获取了 AndroidPlot 的快速入门代码并将其放入提供程序类中,但是当我将其放在主屏幕上时它似乎没有呈现任何内容。

此代码与原始快速入门代码的区别在于,在快速入门中,它利用了 ,Activity.findViewById但显然不能在此处使用。

任何人都可以在这里看到我做错了可能导致空渲染的事情吗?感谢您提供的任何帮助!

private Bitmap getChartImage(Context context)
{

    // initialize our XYPlot reference:
    mySimpleXYPlot = new XYPlot(context, "My Simple XYPlot");

    mySimpleXYPlot.setDrawingCacheEnabled(true);

    // add a new series
    mySimpleXYPlot.addSeries(new SimpleXYSeries(), LineAndPointRenderer.class, new LineAndPointFormatter(Color.rgb(0, 200, 0), Color.rgb(200, 0, 0)));

    // reduce the number of range labels
    mySimpleXYPlot.getGraphWidget().setRangeTicksPerLabel(4);

    // reposition the domain label to look a little cleaner:
    Widget domainLabelWidget = mySimpleXYPlot.getDomainLabelWidget();

    mySimpleXYPlot.position(domainLabelWidget,                     // the widget to position
                            45,                                    // x position value, in this case 45 pixels
                            XLayoutStyle.ABSOLUTE_FROM_LEFT,       // how the x position value is applied, in this case from the left
                            0,                                     // y position value
                            YLayoutStyle.ABSOLUTE_FROM_BOTTOM,     // how the y position is applied, in this case from the bottom
                            AnchorPosition.LEFT_BOTTOM);           // point to use as the origin of the widget being positioned

    // get rid of the visual aids for positioning:
    mySimpleXYPlot.disableAllMarkup();

    //mySimpleXYPlot.measure(150, 150);
    //mySimpleXYPlot.layout(0, 0, 150, 150);


    Bitmap bmp = mySimpleXYPlot.getDrawingCache();

    return bmp;
}
4

1 回答 1

1

你有没有通过查看位图是否真的是空的?我的猜测是位图很好,问题存在于这段代码之外。看一下这个使用 AndroidPlot 的小部件的示例用法- 它非常小而且绝对有效。希望那里有适合您的解决方案:)

缺口

于 2013-06-16T16:33:58.367 回答