16

添付画像のようなグラフを描きたいです。

すでに aChartEngine で試しましたが、うまくいきません。

ここに画像の説明を入力

4

4 に答える 4

15

メソッドで にSurfaceView描画できる を作成できます。グラフを描画するには、クラス、およびメソッドを使用できます。線の外観を変更するには、クラスを使用します。次に、 とオブジェクトを受け取る Canvasesメソッドを使用します。OpenGlよりも少し簡単に始められると思います。CanvasonDraw()PathmoveTo()lineTo()PaintdrawPath()PathPaint

いくつかのチュートリアル

更新: @Shakti Malik は、見栄えの良い、使いやすいライブラリを見つけました: MPAndroidChart

于 2012-09-22T17:44:15.417 に答える
2

OpenGL ES を試してみませんか?

GLSurfaceView を拡張する GraphView を作成できます

サンプルコード-

public class GraphView extends GLSurfaceView {

private Renderer renderer;

public GraphView(Context context) {
    super(context);
    renderer = new GraphRenderer();
    setRenderer(renderer);
}
}

そしてあなたのGraphRender

ublic class GraphRenderer implements Renderer {

public void onDrawFrame(GL10 gl) {
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();

GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 1.0f);
gl.glColor4f(1, 0, 0, .5f);
}

public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);

float ratio = (float) width / height;
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glFrustumf(-ratio, ratio, -1, 1, 3, 7);
}

public void onSurfaceCreated(GL10 gl, EGLConfig config) {

}

private void drawGraph(GL10 gl) {
gl.glLineWidth(1.0f);

// put your code here ..


}

public static int loadShader(int type, String shaderCode) {
int shader = GLES20.glCreateShader(type);
GLES20.glShaderSource(shader, shaderCode);
GLES20.glCompileShader(shader);
return shader;
}

}

この方法で試すことができます。

于 2012-09-22T17:26:27.197 に答える
0
implementation 'com.jjoe64:graphview:4.2.1'

eduGrades = 新しい文字列[5]; behGrades = 新しい文字列[5];

    eduGrades[0] = getString(R.string.fail);
    eduGrades[1] = getString(R.string.pass);
    eduGrades[2] = getString(R.string.good);
    eduGrades[3] = getString(R.string.very_good);
    eduGrades[4] = getString(R.string.excellent);

    behGrades[0] = getString(R.string.baad);
    behGrades[1] = getString(R.string.accepted);
    behGrades[2] =  getString(R.string.good);
    behGrades[3] =  getString(R.string.very_good);
    behGrades[4] =  getString(R.string.excellent);

DataPoint[] eduDp = 新しい DataPoint[results.size()]; DataPoint[] behDp = new DataPoint[results.size()];

            dates = new String[results.size()];

            for (int i = 0; i < results.size(); i++) {

                dates[i] = results.get(i).getDateOfNote();

                eduDp[i] = new DataPoint(i, (double) results.get(i).getEducationEvaluationSign());
                behDp[i] = new DataPoint(i, (double) results.get(i).getBehaviorEvaluationSign());

            }

            LineGraphSeries<DataPoint> eduSeries = new LineGraphSeries<>(eduDp);
            educationalGraphView.addSeries(eduSeries);
            eduSeries.setDrawBackground(true);
            eduSeries.setColor(getResources().getColor(R.color.blue));
            eduSeries.setBackgroundColor(getResources().getColor(R.color.blue));
            StaticLabelsFormatter staticLabelsFormatter;
            staticLabelsFormatter = new StaticLabelsFormatter(educationalGraphView);
            staticLabelsFormatter.setVerticalLabels(eduGrades);
            staticLabelsFormatter.setHorizontalLabels(dates);

            educationalGraphView.getGridLabelRenderer().setHorizontalLabelsColor(getResources().getColor(R.color.colorPrimaryDark));
            educationalGraphView.getGridLabelRenderer().setVerticalLabelsColor(getResources().getColor(R.color.colorPrimaryDark));
            educationalGraphView.getGridLabelRenderer().setGridColor(getResources().getColor(R.color.white));
            educationalGraphView.getGridLabelRenderer().setHorizontalLabelsAngle(145);
            educationalGraphView.getGridLabelRenderer().setTextSize(23f);
            educationalGraphView.getGridLabelRenderer().setLabelsSpace(20);
            educationalGraphView.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);
于 2019-04-17T20:10:59.360 に答える