在我的项目中,我必须以每日净额显示 30 天的条形图。在查看条形图活动时,X 轴标签已折叠并且全部*显示* 没有任何间距。当我单击缩放按钮时,视图被展开,我们可以看到带有相应 x 轴标签的栏。我需要在活动开始时间的扩展视图上显示条形图。
显示条形图的编码:
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(16);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(15);
renderer. setLegendTextSize(15);
// renderer.setInScroll(true);
//renderer.setMargins(new int[]{10,10,10,0});
int length = colors.length;
for (int j = 0; j < length; j++) {
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(colors[j]);
renderer.addSeriesRenderer(r);
}
if(flag==1)
renderer.setChartTitle("Monthly Basis");
if(flag==0)
renderer.setChartTitle("Weekly Basis");
if(flag==2)
renderer.setChartTitle("Yearly Basis");
renderer.setXTitle("Date");
renderer.setYTitle("NetAmount");
renderer.setXAxisMin(0);
//renderer
renderer.setYAxisMin(100);
// renderer.setYAxisMax(35000);
renderer.setAxesColor(Color.GRAY);
renderer.setLabelsColor(Color.LTGRAY);
renderer.setXLabels(0);
//renderer.setYLabels(31);
renderer.setDisplayChartValues(true);
renderer.setXLabelsAlign(Align.LEFT);
renderer.setYLabelsAlign(Align.RIGHT);
if(flag==0 || flag==1)
{
for(int axis=1;axis<=31;axis++)
{
String d;
d=String.valueOf(axis);
renderer.addTextLabel(axis,d);
}
}
else
{
renderer.setXAxisMin(2005);
for(int axis=2005;axis<=2011;axis++)
{
String d;
d=String.valueOf(axis);
renderer.addTextLabel(axis,d);
}
// renderer.setXLabels(4);
}
//renderer.setPanEnabled(false,false);
//renderer.setZoomEnabled(false,false);
// renderer.setPanLimits(new double[] { 0, 32, -10, 40 });
// renderer.setZoomLimits(new double[] { 0, 32, -10, 40 });
renderer.setZoomRate(3.0f);
renderer.setBarSpacing(0.25);
//renderer.set(new double[] {0,30,100,35000});
//Intent in;
List<double[]> xvalues = new ArrayList<double[]>();
int count=1,j=0;
if(flag==0 || flag==1)
{
double xdata[]=new double[31];
while(count<32)
{
xdata[j]=count;
count++;
j++;
}
xvalues.add(xdata);
}
if(flag==2)
{
double xdata[]=new double[7];
count=2005;
while(j<7)
{
xdata[j]=count;
count++;
j++;
}
xvalues.add(xdata);
}
// return ChartFactory.getBarChartIntent(context, buildBarDataset(titles,xvalues,values), renderer,
// Type.DEFAULT);
mchart=ChartFactory.getBarChartView(context,buildBarDataset(titles,xvalues,values), renderer, Type.STACKED);
//LinearLayout layout = (LinearLayout) findViewById(R.id.chart1);
layout.addView(mchart);
mchart.repaint();
//startActivity(in);
}
protected XYMultipleSeriesDataset buildBarDataset(String[] titles, List<double[]> xvalues, List<double[]> values) {
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
int length = titles.length;
for (int i = 0; i < length; i++) {
//CategorySeries series = new CategorySeries(titles[i]);
XYSeries series = new XYSeries(titles[i]);
double[] v = values.get(i);
double[]x=xvalues.get(i);
int seriesLength = v.length;
for (int k = 0; k < seriesLength; k++) {
if(v[k]==0)
{
v[k]=MathHelper.NULL_VALUE;
}
else
{
series.add(x[k],v[k]);
}
//Log.i("Invent","X Axis"+x[k]);
//series.add(xdata[k],v[k]);
}
dataset.addSeries(series);
for (int k = 0; k < seriesLength; k++) {
if(v[k]==MathHelper.NULL_VALUE)
{
v[k]=0;
}
}
}
return dataset;
}
}