我只是用achartengine创建一个新图表,我注意到当我移动图表时它会越过x和y轴。感谢Dan这个问题通过将我的achartengine更新到1.1.0 ver来解决。 无论如何,我看到这个问题已经解决了achartengine demoes但我无法理解为什么它不能解决我的图表中的问题。
我想我做错了,我的xml代码是:
<RelativeLayout
android:id="@+id/rlMyChartsGridDown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/rlMyChartsTopGrid"
android:background="@drawable/weeks_grid_down" >
<LinearLayout
android:id="@+id/chart"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
/>
我的java代码是:
public GraphicalView weightView(Context context) {
manageData = new ManageData(context);
TimeSeries series = new TimeSeries("The day");
TimeSeries maxSeries = new TimeSeries("Max Weight");
TimeSeries minSeries = new TimeSeries("Min Weight");
int count = 0;
float sum = 0;
float max = 0;
int preWeek = 0;
manageData.open();
cursor = manageData.getProfile();
manageData.close();
if ((cursor.moveToFirst()) && (cursor.getCount() != 0)) {
weightUnit = cursor.getString(C_PROFILE_WEIGHT_UNIT);
weight = cursor.getFloat(C_PROFILE_WEIGHT);
bmi = cursor.getFloat(C_PROFILE_BMI);
weightGain();
cursor.close();
minSeries.add(0,weight);
maxSeries.add(0,weight);
minSeries.add(12,weight+1);
maxSeries.add(12,weight+2);
minSeries.add(42,weight+minWeight);
maxSeries.add(42,weight+maxWeight);
}
manageData.open();
Cursor cursor = manageData.getDiaryInfo();
manageData.close();
cursor.moveToFirst();
if (cursor.getCount() > 0) {
preWeek = cursor.getInt(DIARY_WEEK);
}
while (!cursor.isAfterLast()) {
if ((cursor.getInt(DIARY_WEEK) == preWeek)
&& (cursor.getFloat(WEIGHT) != 0)) {
count++;
sum = sum + cursor.getFloat(WEIGHT);
cursor.moveToNext();
} else {
if (count != 0) {
series.add(preWeek, sum / count);
if (max < sum / count) {
max = sum / count;
}
}
sum = 0;
count = 0;
preWeek = cursor.getInt(DIARY_WEEK);
if (cursor.getFloat(WEIGHT) != 0) {
count++;
sum = sum + cursor.getFloat(WEIGHT);
}
cursor.moveToNext();
}
}
if (max < sum / count) {
max = sum / count;
}
series.add(preWeek, sum / count);
cursor.close();
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(series);
dataset.addSeries(minSeries);
dataset.addSeries(maxSeries);
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
// Customization Weight line
XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setColor(0xff154916);
renderer.setLineWidth(3);
renderer.setPointStyle(PointStyle.CIRCLE);
renderer.setFillPoints(true);
// Customization maxWeight line
XYSeriesRenderer rendererMax = new XYSeriesRenderer();
rendererMax.setColor(0xff8EC239);
rendererMax.setLineWidth(2);
// Customization minWeight line
XYSeriesRenderer rendererMin = new XYSeriesRenderer();
rendererMin.setColor(0xffF7931E);
rendererMin.setLineWidth(2);
mRenderer.setMargins(new int[] {20, 35, 20, 20 });
mRenderer.setApplyBackgroundColor(true);
mRenderer.setBackgroundColor(Color.TRANSPARENT);
mRenderer.setMarginsColor(color);
mRenderer.addSeriesRenderer(renderer);
mRenderer.addSeriesRenderer(rendererMax);
mRenderer.addSeriesRenderer(rendererMin);
mRenderer.setYLabelsColor(0, Color.BLACK);
mRenderer.setXLabelsColor(Color.BLACK);
mRenderer.setLabelsTextSize(18);
mRenderer.setAxesColor(Color.BLACK);
mRenderer.setLabelsColor(Color.BLACK);
mRenderer.setYLabelsAlign(Align.RIGHT);
// mRenderer.setYAxisAlign(Align.LEFT, 0);
mRenderer.setXTitle("Week");
if(weightUnit.equals("kg")){
mRenderer.setYTitle("Weight (kg)");
} else {
mRenderer.setYTitle("Weight (lb)");
}
mRenderer.setZoomButtonsVisible(true);
mRenderer.setLabelsColor(0xff418614);
mRenderer.setLegendTextSize(15);
mRenderer.setPointSize(5);
// mRenderer.setZoomEnabled(false, false);
// mRenderer.setPanEnabled(true, false);
mRenderer.setXAxisMax(43);
mRenderer.setXAxisMin(0);
if(max>maxWeight + weight){
mRenderer.setYAxisMax(max + 10);
} else {
mRenderer.setYAxisMax(maxWeight + weight + 10);
}
mRenderer.setYAxisMin(0);
return ChartFactory.getLineChartView(context, dataset, mRenderer);
}
我的主要java代码是:
public void onClick(View v) {
switch (v.getId()) {
case R.id.tbMyChartsWeight:
tbMyChartsWeight.setChecked(true);
tbMyChartsWaist.setChecked(false);
tbMyChartsMood.setChecked(false);
line = new LineGraph();
gView = line.weightView(this);
layout = (LinearLayout) findViewById(R.id.chart);
layout.removeAllViews();
layout.addView(gView);
return;
case R.id.tbMyChartsWaist:
tbMyChartsWeight.setChecked(false);
tbMyChartsWaist.setChecked(true);
tbMyChartsMood.setChecked(false);
line = new LineGraph();
gView = line.waistView(this);
layout = (LinearLayout) findViewById(R.id.chart);
layout.removeAllViews();
layout.addView(gView);
return;
case R.id.tbMyChartsMood:
tbMyChartsWeight.setChecked(false);
tbMyChartsWaist.setChecked(false);
tbMyChartsMood.setChecked(true);
line = new LineGraph();
gView = line.mentalView(this);
layout = (LinearLayout) findViewById(R.id.chart);
layout.removeAllViews();
layout.addView(gView);
return;
default:
break;
}
}
我希望有人可以帮助我 我很抱歉我的英语不好 谢谢大家:]
答案 0 :(得分:1)
您使用的是透明背景。您可以使用其他背景类型或不设置任何背景来解决此问题。