简体   繁体   English

Android 雷达图

[英]Radar Chart for Android

I wonder if is possible replicate this kind of graph in Android.我想知道是否可以在 Android 中复制这种图形。图

The data is not important to be entered directly from the image, will be entered on a previous screen.直接从图像输入的数据并不重要,将在上一个屏幕上输入。

If not possible recreate a similar chart (I think it's pretty hard in fact) is possible use a simple spider graph, but the important thing is that can insert two different series and they have their own labels.如果不可能重新创建一个类似的图表(我认为这实际上很难)可以使用一个简单的蜘蛛图,但重要的是可以插入两个不同的系列并且它们有自己的标签。

In fact, notice that the labels capitalized form a surface, while those written in lower case will form another.事实上,请注意大写的标签形成一个表面,而小写的标签将形成另一个。 You say that you can do such a thing?你说你能做这种事?

I found this library ( https://code.google.com/p/charts4j/ ) who also does graphic spider chart, but I can not enter a different series with his "legend"!我找到了这个库( https://code.google.com/p/charts4j/ ),他也做图形蜘蛛图,但我不能用他的“传奇”输入不同的系列!

I have partially solved in the design of the chart!我在图表的设计中已经部分解决了! Now I can draw exactly the same form and enter the data correctly.现在我可以绘制完全相同的表格并正确输入数据。 In particular, I created a custom View that extending the ImageView and on onDraw (Canvas canvas) I added the following code: (The code is not optimized at all, I know, it's just to run tests quickly )特别是,我创建了一个扩展 ImageView 的自定义视图,并在onDraw(Canvas 画布)上添加了以下代码:(代码根本没有优化,我知道,只是为了快速运行测试)

    @Override 
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        Paint paint = new Paint();
        Paint paint_cibo = new Paint();
        Paint paint_vino = new Paint();
        Paint paint_text = new Paint();

        final float x = getWidth() * 1.5f;
        final float y = getHeight() * 1.5f;

        final int[] valori_cibo = new int[]{2, 5, 4, 8, 3, 5};
        final int[] valori_vino = new int[]{6, 7, 7, 6, 6, 6};

        canvas.drawColor(Color.WHITE);

        paint.setAntiAlias(true);
        paint.setColor(Color.BLACK);
        paint.setStyle(Paint.Style.STROKE); 
        paint.setStrokeWidth(2f);

        paint_cibo.setAntiAlias(true);
        paint_cibo.setColor(Color.BLUE);
        paint_cibo.setStyle(Paint.Style.STROKE);
        paint_cibo.setStrokeWidth(2f);

        paint_vino.setAntiAlias(true);
        paint_vino.setColor(Color.RED);
        paint_vino.setStyle(Paint.Style.STROKE);
        paint_vino.setStrokeWidth(2f);

        paint_text.setAntiAlias(true);
        paint_text.setColor(Color.BLACK);
        paint_text.setStyle(Paint.Style.FILL);
        paint_text.setTextSize(10);

        // Draw the circles
        for(int i = 1; i <= 110; i += 10)
            canvas.drawCircle(x, y, i, paint);

        // Draw the intersection lines
        canvas.drawLine(x + 10, y - 2.5f, (float)(x + 10 + 110 * Math.cos(returnGradi(90))), (float)(y - 2.5f - 110 * Math.sin(returnGradi(90))), paint);

        canvas.drawLine(x, y, (float)(x + 110 * Math.cos(returnGradi(45))), (float)(y - 110 * Math.sin(returnGradi(45))), paint);
        canvas.drawLine(x, y, (float)(x + 110 * Math.cos(returnGradi(30))), (float)(y - 110 * Math.sin(returnGradi(30))), paint);

        canvas.drawLine(x + 10, y - 5, (float)(x + 10 + 110 * Math.cos(returnGradi(315))), (float)(y - 5 - 110 * Math.sin(returnGradi(315))), paint);
        canvas.drawLine(x, y + 8, (float)(x + 110 * Math.cos(returnGradi(315))), (float)(y + 8 - 110 * Math.sin(returnGradi(315))), paint);

        canvas.drawLine(x, y, (float)(x + 110 * Math.cos(returnGradi(280))), (float)(y - 110 * Math.sin(returnGradi(280))), paint);
        canvas.drawLine(x, y, (float)(x + 110 * Math.cos(returnGradi(260))), (float)(y - 110 * Math.sin(returnGradi(260))), paint);

        canvas.drawLine(x - 10, y - 5, (float)(x - 10 + 110 * Math.cos(returnGradi(225))), (float)(y - 5 - 110 * Math.sin(returnGradi(225))), paint);
        canvas.drawLine(x, y + 8, (float)(x + 110 * Math.cos(returnGradi(225))), (float)(y + 8 - 110 * Math.sin(returnGradi(225))), paint);

        canvas.drawLine(x - 10, y - 2.5f, (float)(x - 10 + 110 * Math.cos(returnGradi(90))), (float)(y - 2.5f - 110 * Math.sin(returnGradi(90))), paint);
        canvas.drawLine(x, y, (float)(x + 110 * Math.cos(returnGradi(135))), (float)(y - 110 * Math.sin(returnGradi(135))), paint);
        canvas.drawLine(x, y, (float)(x + 110 * Math.cos(returnGradi(150))), (float)(y - 110 * Math.sin(returnGradi(150))), paint);

        // Draw the numbers
        for(int i = 1; i <= 10; i++)
            canvas.drawText(String.valueOf(i), x - 2.5f, y - i * 10, paint_text);


        //Start drawing food
        canvas.drawLine((float)(x + valori_cibo[0] * 10 * Math.cos(returnGradi(45))), (float)(y - valori_cibo[0] * 10 * Math.sin(returnGradi(45))), (float)(x + valori_cibo[1] * 10 * Math.cos(returnGradi(30))), (float)(y - valori_cibo[1] * 10 * Math.sin(returnGradi(30))), paint_cibo);
        canvas.drawLine((float)(x + valori_cibo[1] * 10 * Math.cos(returnGradi(30))), (float)(y - valori_cibo[1] * 10 * Math.sin(returnGradi(30))), (float)(x + valori_cibo[2] * 10 * Math.cos(returnGradi(280))), (float)(y - valori_cibo[2] * 10 * Math.sin(returnGradi(280))), paint_cibo);
        canvas.drawLine((float)(x + valori_cibo[2] * 10 * Math.cos(returnGradi(280))), (float)(y - valori_cibo[2] * 10 * Math.sin(returnGradi(280))), (float)(x + valori_cibo[3] * 10 * Math.cos(returnGradi(260))), (float)(y - valori_cibo[3] * 10 * Math.sin(returnGradi(260))), paint_cibo);
        canvas.drawLine((float)(x + valori_cibo[3] * 10 * Math.cos(returnGradi(260))), (float)(y - valori_cibo[3] * 10 * Math.sin(returnGradi(260))), (float)(x + valori_cibo[4] * 10 * Math.cos(returnGradi(150))), (float)(y - valori_cibo[4] * 10 * Math.sin(returnGradi(150))), paint_cibo);
        canvas.drawLine((float)(x + valori_cibo[4] * 10 * Math.cos(returnGradi(150))), (float)(y - valori_cibo[4] * 10 * Math.sin(returnGradi(150))), (float)(x + valori_cibo[5] * 10 * Math.cos(returnGradi(135))), (float)(y - valori_cibo[5] * 10 * Math.sin(returnGradi(135))), paint_cibo);
        canvas.drawLine((float)(x + valori_cibo[5] * 10 * Math.cos(returnGradi(135))), (float)(y - valori_cibo[5] * 10 * Math.sin(returnGradi(135))), (float)(x + valori_cibo[0] * 10 * Math.cos(returnGradi(45))), (float)(y - valori_cibo[0] * 10 * Math.sin(returnGradi(45))), paint_cibo);

        //Start drawing Wine
        canvas.drawLine((float)(x + 10 + valori_vino[0] * 10 * Math.cos(returnGradi(90))), (float)(y - valori_vino[0] * 10 * Math.sin(returnGradi(90))), (float)(x + 10 + valori_vino[1] * 10 * Math.cos(returnGradi(315))), (float)(y - 5 - valori_vino[1] * 10 * Math.sin(returnGradi(315))), paint_vino);
        canvas.drawLine((float)(x + 10 + valori_vino[1] * 10 * Math.cos(returnGradi(315))), (float)(y - 5 - valori_vino[1] * 10 * Math.sin(returnGradi(315))), (float)(x + 5 + valori_vino[3] * 10 * Math.cos(returnGradi(315))), (float)(y + 10 - valori_vino[3] * 10 * Math.sin(returnGradi(315))), paint_vino);
        canvas.drawLine((float)(x + 5 + valori_vino[3] * 10 * Math.cos(returnGradi(315))), (float)(y + 10 - valori_vino[3] * 10 * Math.sin(returnGradi(315))), (float)(x + 5 + valori_vino[3] * 10 * Math.cos(returnGradi(225))), (float)(y + 5 - valori_vino[3] * 10 * Math.sin(returnGradi(225))), paint_vino);
        canvas.drawLine((float)(x + 5 + valori_vino[3] * 10 * Math.cos(returnGradi(225))), (float)(y + 5 - valori_vino[3] * 10 * Math.sin(returnGradi(225))), (float)(x - 5 + valori_vino[4] * 10 * Math.cos(returnGradi(225))), (float)(y - 8 - valori_vino[4] * 10 * Math.sin(returnGradi(225))), paint_vino);
        canvas.drawLine((float)(x - 5 + valori_vino[4] * 10 * Math.cos(returnGradi(225))), (float)(y - 8 - valori_vino[4] * 10 * Math.sin(returnGradi(225))), (float)(x - 10 + valori_vino[5] * 10 * Math.cos(returnGradi(90))), (float)(y - valori_vino[5] * 10 * Math.sin(returnGradi(90))), paint_vino);
        canvas.drawLine((float)(x - 10 + valori_vino[5] * 10 * Math.cos(returnGradi(90))), (float)(y - valori_vino[5] * 10 * Math.sin(returnGradi(90))), (float)(x + 10 + valori_vino[0] * 10 * Math.cos(returnGradi(90))), (float)(y - valori_vino[0] * 10 * Math.sin(returnGradi(90))), paint_vino);
}

I repeat, not to consider the poorly optimized code... It's possible to implement some sort of zoom that maintaining the focus zoom in center of the circle's center?我再说一遍,不要考虑优化不佳的代码......是否可以实现某种缩放以保持圆心中心的焦点缩放?

查看GitHub上的Android-Charts项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM