AchartEngine XYchart background color problem
I have a problem with xychart with achart engine. In practice, the background color is set only within the axis area. my code:
private XYMultipleSeriesDataset mDataset = new XYMultipleSeriesDataset();
private XYMultipleSeriesRenderer mRendererXY = new XYMultipleSeriesRenderer();
private XYSeries mSeriesXY;
private GraphicalView mXYView;
private ViewFlinger mFlingy;
private int index = 0;
public StatChallengeTabManager(Context ctx, ViewFlinger flingy) {
mCtx = ctx;
mFlingy = flingy;
mStatDBManagerCh = new StatDBManagerChallenge(ctx);
}
public void drawStats() {
LayoutInflater inflate = (LayoutInflater) mCtx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v1 = inflate.inflate(R.layout.v1, null);
v2 = inflate.inflate(R.layout.v2, null);
mFlingy.addView(v1);
mFlingy.addView(v2);
drawFirstChart();
drawSecondChart();
}
private void drawFirstChart() {
if (mXYView == null) {
mRendererXY.setAxisTitleTextSize(30);
mRendererXY.setChartTitleTextSize(40);
mRendererXY.setChartTitle(mCtx.getString(R.string.score_trend));
mRendererXY.setLabelsColor(Color.BLACK);
mRendererXY.setXLabelsColor(Color.BLACK);
mRendererXY.setYLabelsColor(0, Color.BLACK);
mRendererXY.setMargins(new int[] { 50, 60, 0, 50 });
mRendererXY.setLabelsTextSize(30);
mRendererXY.setZoomButtonsVisible(false);
mRendererXY.setPointSize(8);
mRendererXY.setDisplayValues(true);
mRendererXY.setShowLegend(false);
mRendererXY.setScale(.8f);
XYSeriesRenderer r = new XYSeriesRenderer();
r.setColor(COLORS[0]);
r.setPointStyle(PointStyle.CIRCLE);
r.setFillBelowLine(false);
r.setFillPoints(true);
mRendererXY.addSeriesRenderer(r);
mRendererXY.setXTitle(mCtx.getString(R.string.game_id));
mRendererXY.setYTitle(mCtx.getString(R.string.game_score));
mRendererXY.setFitLegend(true);
mRendererXY.setAxesColor(Color.BLACK);
mRendererXY.setShowGrid(true);
mRendererXY.setXAxisMin(-0.5);
mRendererXY.setYAxisMin(0);
mRendererXY.setXAxisMax(10.5);
mRendererXY.setZoomEnabled(false);
mRendererXY.setYAxisMax(100000);
mRendererXY.setInScroll(true);
mRendererXY.setClickEnabled(true);
mRendererXY.setBackgroundColor(Color.argb(255, 255, 248, 220));
mRendererXY.setApplyBackgroundColor(true);
int[] res = mStatDBManagerCh.getGameScores();
mSeriesXY = new XYSeries(mCtx.getString(R.string.score_trend));
for (int i = 0; i < res.length; i++) {
if (res[i] == 0)
continue;
mSeriesXY.add(i, res[i]);
}
mDataset.addSeries(mSeriesXY);
mXYView = ChartFactory.getLineChartView(mCtx, mDataset, mRendererXY);
LinearLayout layout = (LinearLayout) v1.findViewById(R.id.chart1);
layout.addView(mXYView, new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
} else {
LinearLayout layout = (LinearLayout) v1.findViewById(R.id.chart1);
layout.addView(mXYView, new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
mXYView.repaint();
}
}
Whereas v1.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/chart1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" />
</LinearLayout>
And the result is https://www.dropbox.com/s/z2wuq1j0bjwz1wj/problem.png
+3
source to share