我想在我的Activity中整合一个简单的XY折线图。在寻找自定义(可定制背景,颜色,轴标签)的免费图表时,我发现了两个候选人:Achartengine和Adnroidplot。还有一些其他库,但它们不是可定制的或仅作为单独的意图提供。Android上的图表 - androidplot和achartengine的问题
我还需要支持较旧的Android API(必须支持至少1.6)。
我试过Achartengine,但是当我将它集成到一个ScrollView中时失败了。当我滚动时,图表变得不知何故被损坏,它被挤压,一些背景元素似乎飘走了。
然后我试了Adnroidplot。起初它并不是从1.6开始的,因为Pair类。但我在Adnroidplot论坛上发现了一个修复问题。一切似乎工作正常,也动态更新,虽然自定义观察员工作正常。自定义X轴标签有点难(我需要自定义字符串而不是数字),但是使用自定义格式化程序我终于做到了。
但后来我试着用客户端数据库中的真实数据进行测试。有一系列具有相同值的点。我很震惊地看到,Adnroidplot无法画出水平线,它挂起或完全弄乱了图表!
下面是测试情况下,我从Adnroidplot快速入门借来的,做了小的修改,使一个系列用相等值:
pricesPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
// Create array of y-values to plot:
Number[] series1Numbers = {7, 7}; // horizontal line expected, got nothing or hang
// Turn the above arrays into XYSeries:
XYSeries series1 = new SimpleXYSeries(
Arrays.asList(series1Numbers), // SimpleXYSeries takes a List so turn our array into a List
ArrayFormat.Y_VALS_ONLY, // Y_VALS_ONLY means use the element index as the x value
"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
null); // fill color (optional) <- my app hangs if I add it for a horizontal line
// Add series1 to the xyplot:
pricesPlot.addSeries(series1, series1Format);
// Reduce the number of range labels
pricesPlot.setTicksPerRangeLabel(3);
// By default, AndroidPlot displays developer guides to aid in laying out your plot.
// To get rid of them call disableAllMarkup():
pricesPlot.disableAllMarkup();
我已经张贴在Adnroidplot论坛,但我不知道有多快他们会回答,问题何时会得到解决。
所以我希望也许有人在StackOverflow可能知道一些解决方法吗?
退房的解决办法,我想出了以绘制一个水平线,或者我应该说,让你的横线显示在AndroidPlot中。 – whyoz 2014-02-06 00:22:34