gpt4 book ai didi

android - AchartEngine XYchart背景颜色问题

转载 作者:太空宇宙 更新时间:2023-11-03 12:58:59 25 4
gpt4 key购买 nike

我在使用图表引擎的 xychart 中遇到问题。实际上,背景颜色仅在轴区域内设置。我的代码:

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();
}

}

虽然 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>

结果是https://www.dropbox.com/s/z2wuq1j0bjwz1wj/problem.png

最佳答案

只需调用 mRendererXY.setMarginsColor(color); 即可设置边距背景。

关于android - AchartEngine XYchart背景颜色问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14459971/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com