Androidplot-不在景观中显示
如果我使用Androidplot绘制条形图,然后将手机方向从纵向改为横向,所有图表信息都会消失。(链接到屏幕截图) 横向-无图表数据 纵向-图表数据 经过一些尝试和错误,我发现如果我将图表宽度设置为设备屏幕宽度的0.96,所有图表信息都会再次出现 如何让Androidplot在横向环境中占据100%的设备屏幕宽度 我创建图表的代码可以在找到Androidplot-不在景观中显示,android,androidplot,Android,Androidplot,如果我使用Androidplot绘制条形图,然后将手机方向从纵向改为横向,所有图表信息都会消失。(链接到屏幕截图) 横向-无图表数据 纵向-图表数据 经过一些尝试和错误,我发现如果我将图表宽度设置为设备屏幕宽度的0.96,所有图表信息都会再次出现 如何让Androidplot在横向环境中占据100%的设备屏幕宽度 我创建图表的代码可以在找到 private View createBarGraph() { // initialize our XYPlot refere
private View createBarGraph()
{
// initialize our XYPlot reference:
XYPlot plot = (XYPlot) this.findViewById(R.id.mySimpleXYPlot1);
// Create a couple arrays of y-values to plot:
Number[] series1Numbers = GenerateGraphValues();
// Turn the above arrays into XYSeries':
XYSeries series1 = new SimpleXYSeries(Arrays.asList(series1Numbers),
SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, // Y_VALS_ONLY means use the
// element index as the x value
"Series1"); // Set the display title of the series
BarFormatter series1Format = new BarFormatter(Color.rgb(51, 181, 229), Color.TRANSPARENT);
PointLabelFormatter plf = new PointLabelFormatter();
plf.getTextPaint().setTextSize(18);
plf.getTextPaint().setColor(Color.BLACK);
series1Format.setPointLabelFormatter(plf);
series1Format.setPointLabeler(new PointLabeler(){
DecimalFormat df = new DecimalFormat("##0.00");
public String getLabel(XYSeries series, int index)
{
// need to check for null
if(series.getY(index) == null) return "";
return df.format(series.getY(index));
}
});
// add a new series' to the xyplot:
plot.addSeries(series1, series1Format);
// Y axis config
plot.setRangeLabel("Values"); // label
plot.setRangeBoundaries(0, 110, BoundaryMode.FIXED); // scale
plot.setRangeStep(XYStepMode.INCREMENT_BY_VAL, 10); // steps
plot.getGraphWidget().getRangeLabelPaint().setTextSize(26); // font size
DecimalFormat nf = new DecimalFormat("#0");
plot.setRangeValueFormat(nf);
// X Axs config
plot.setDomainLabel("Indexes");
plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 1);
plot.getGraphWidget().setDomainValueFormat(new DecimalFormat("0"));
plot.getGraphWidget().getDomainLabelPaint().setTextSize(18);
plot.getGraphWidget().setMarginTop(20);
plot.getGraphWidget().setMarginBottom(15);
plot.getGraphWidget().setMarginLeft(15);
plot.getGraphWidget().setMarginRight(15);
// plot.getLegendWidget().setHeight(14);
plot.getGraphWidget().setGridPaddingLeft(15);
plot.getGraphWidget().setGridPaddingRight(15);
// plot.getGraphWidget().setGridPaddingBottom(20);
// other config
plot.getLegendWidget().setVisible(false); // hide legend
plot.getGraphWidget().getDomainGridLinePaint().setColor(Color.TRANSPARENT); // hide
// grid
// lines
plot.getGraphWidget().getRangeGridLinePaint().setColor(Color.TRANSPARENT); // hide
// grid
// lines
// plot.getGraphWidget().setGridPaddingLeft(40); // give some padding
// plot.getGraphWidget().setGridPaddingRight(40); // give some padding
plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE); // background
// color
// plot.getTitleWidget().setPaddingTop(10); // give some padding
// set bar width
BarRenderer<?> renderer = (BarRenderer<?>) plot.getRenderer(BarRenderer.class);
renderer.setBarWidth(20);
return plot;
}
private View createBarGraph()
{
//初始化XYPlot引用:
XYPlot=(XYPlot)this.findViewById(R.id.mySimpleXYPlot1);
//创建要打印的两个y值数组:
Number[]series1Numbers=GenerateGraphValues();
//将上述阵列转换为XYSeries':
XYSeries series1=新的SimpleXYSeries(Arrays.asList(series1Number)),
SimpleXYSeries.ArrayFormat.Y\u VALS\u ONLY,//Y\u VALS\u ONLY表示使用
//元素索引作为x值
“序列1”);//设置序列的显示标题
BarFormatter series1Format=新的BarFormatter(Color.rgb(51181229),Color.TRANSPARENT);
PointLabelFormatter plf=新的PointLabelFormatter();
plf.getTextPaint().setTextSize(18);
plf.getTextPaint().setColor(Color.BLACK);
系列1格式设定点标签格式(plf);
series1Format.setPointLabeler(新的PointLabeler(){
DecimalFormat df=新的DecimalFormat(“##0.00”);
公共字符串getLabel(XYSeries系列,int索引)
{
//需要检查null
if(series.getY(index)==null)返回“”;
返回df.format(series.getY(index));
}
});
//向xyplot添加新系列:
绘图。添加系列(系列1、系列1格式);
//Y轴配置
plot.setRangeLabel(“值”);//标签
plot.setRangeBounders(0,110,BoundaryMode.FIXED);//比例
plot.setRangeStep(xystemode.INCREMENT_BY_VAL,10);//步数
plot.getGraphWidget().getRangeLabelPaint().setTextSize(26);//字体大小
DecimalFormat nf=新的DecimalFormat(#0”);
plot.setRangeValueFormat(nf);
//X Axs配置
plot.setDomainLabel(“索引”);
plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL,1);
plot.getGraphWidget().setDomainValueFormat(新的DecimalFormat(“0”));
plot.getGraphWidget().getDomainLabelPaint().setTextSize(18);
plot.getGraphWidget().setMarginTop(20);
plot.getGraphWidget().setMarginBottom(15);
plot.getGraphWidget().setMarginLeft(15);
plot.getGraphWidget().setMarginRight(15);
//plot.getLegendWidget().setHeight(14);
plot.getGraphWidget().setGridPaddingLeft(15);
plot.getGraphWidget().setGridPaddingRight(15);
//plot.getGraphWidget().setGridPaddingBottom(20);
//其他配置
plot.getLegendWidget().setVisible(false);//隐藏图例
plot.getGraphWidget().getDomainGridLinePaint().setColor(Color.TRANSPARENT);//隐藏
//网格
//线条
plot.getGraphWidget().getRangeGridLinePaint().setColor(Color.TRANSPARENT);//隐藏
//网格
//线条
//plot.getGraphWidget().setGridPaddingLeft(40);//提供一些填充
//plot.getGraphWidget().setGridPaddingRight(40);//提供一些填充
plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);//背景
//颜色
//plot.getTitleWidget().setPaddingTop(10);//提供一些填充
//设置栏宽
BarRenderer renderer=(BarRenderer)plot.getRenderer(BarRenderer.class);
1.立根宽度(20);
回归图;
}
如果在条形图活动上运行上述实验,会发生什么?它表现出同样的行为吗?它在我的设备上工作。不,图表以横向模式显示。如果在运行我的代码时,它是否显示出错误的行为?请在此处标记它在两种模式下都出现。但在纵向模式下,它会收缩。