Android极坐标图

Android极坐标图,android,graph,achartengine,Android,Graph,Achartengine,我试着做一些类似的事情,但我对它的外观有一点灵活性。本质上要么是一个饼图,只填充了饼图的一部分,其余部分留空,要么是某种拨号表 使用极坐标图绘制两个箭头也相对容易,一个在0度,一个在-92度,但我找不到任何库可以让你在Android上这样做。我确实需要它使0度看起来像0极度 我使用了一个AChartEngine拨号表,并设法接近一些,但我不知道如何让标签显示每个箭头。我试过renderer.setDisplayValuestrue;和series.setDisplayChartValuestru

我试着做一些类似的事情,但我对它的外观有一点灵活性。本质上要么是一个饼图,只填充了饼图的一部分,其余部分留空,要么是某种拨号表

使用极坐标图绘制两个箭头也相对容易,一个在0度,一个在-92度,但我找不到任何库可以让你在Android上这样做。我确实需要它使0度看起来像0极度

我使用了一个AChartEngine拨号表,并设法接近一些,但我不知道如何让标签显示每个箭头。我试过renderer.setDisplayValuestrue;和series.setDisplayChartValuestrue; 但它不会显示我的两个箭头的值,所以我不确定是否可以使用拨号表。我意识到,如果我在后台显示拨号盘的标签,我的用户就不需要在箭头上有标签,但我正在旋转拨号表添加到的线性布局,以便使0看起来像极坐标图中的0度。尽管使用renderer.setShowLabelsfalse,我还是在努力在后台隐藏拨号盘的标签;把你能展示的所有东西都设置为false。我的方法是将标签颜色设置为背景色,但如果有更好的方法,请告诉我

这是我的拨号表代码

CategorySeries category = new CategorySeries("Angle");
category.add("Extension", 0);
category.add("Flexion", 90);

renderer = new DialRenderer();
renderer.setLabelsColor(getActivity().getResources().getColor(R.color.background));

renderer.setInScroll(true);
renderer.setDisplayValues(true);

renderer.setShowLegend(false);
renderer.setShowAxes(false);
renderer.setShowLabels(false);
renderer.setShowGrid(false);
renderer.setMargins(new int[] {20, 30, 15, 0});
renderer.setVisualTypes(new DialRenderer.Type[] {Type.ARROW, Type.ARROW});
renderer.setMinValue(-20);
renderer.setMaxValue(280);
renderer.setPanEnabled(false);
renderer.setZoomEnabled(false);

SimpleSeriesRenderer r = new SimpleSeriesRenderer();
series.setColor(getActivity().getResources().getColor(R.color.green));
series.setDisplayChartValues(true);
series.setChartValuesTextSize(30);
visualizationRenderer.addSeriesRenderer(r);

r = new SimpleSeriesRenderer();
series.setColor(getActivity().getResources().getColor(R.color.green));
series.setDisplayChartValues(true);
series.setChartValuesTextSize(30);
renderer.addSeriesRenderer(r);

visualization = ChartFactory.getDialChartView(getActivity(), category, renderer);

LinearLayout layout = (LinearLayout) this.getView().findViewById(R.id.sessions_visualization);
layout.addView(visualization);

layout.setRotation(220.0f);

我愿意修改这段代码来获得一些有用的东西,或者使用其他库来帮助我完成我要做的事情。谢谢

我在回答我自己的问题,希望以后有人能像这样做

您可以在Android中创建自定义视图,并绘制您想要显示的任何内容。有很好的文档

下面是一段相关的代码片段。这并不完美,但它确实起到了作用

public class AngleVisualization extends View {
    private Paint textPaint;
    private Paint arcPaint;
    private Paint linePaint;
    RectF oval;
    private float extension;
    private float flexion;
    private int textColor;
    private int arcColor;
    private float extensionLabelX;
    private float extensionLabelY;
    private float flexionLabelX;
    private float flexionLabelY;

    private Rect extensionBounds = new Rect();


    public AngleVisualization(Context context, AttributeSet attrs) {
        super(context, attrs);
        TypedArray a = context.getTheme().obtainStyledAttributes(
            attrs,
            R.styleable.AngleVisualization,
            0, 0);

    try {
        extension = a.getFloat(R.styleable.AngleVisualization_extensionValue, 0);
        flexion = a.getFloat(R.styleable.AngleVisualization_flexionValue, 0);
        textColor = a.getColor(R.styleable.AngleVisualization_textColor, Color.BLACK);
        arcColor = a.getColor(R.styleable.AngleVisualization_arcColor, context.getResources().getColor(R.color.green));
        extensionLabelX = a.getDimension(R.styleable.AngleVisualization_extensionLabelX, 190);
        extensionLabelY = a.getDimension(R.styleable.AngleVisualization_extensionLabelY, 150);
        flexionLabelX = a.getDimension(R.styleable.AngleVisualization_flexionLabelX, 50);
        extensionLabelY = a.getDimension(R.styleable.AngleVisualization_flexionLabelY, 190);

    } finally {
        a.recycle();
    }

    oval = new RectF();

    init();
}

private void init() {
    textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setColor(textColor);
    textPaint.setTextSize(30);

    arcPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    arcPaint.setColor(arcColor);

    linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    linePaint.setColor(arcColor);
    linePaint.setStrokeWidth(3);
}

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    String extensionString = decimalFormat.format(extension) + "˚";
    textPaint.getTextBounds(extensionString, 0, extensionString.length(), extensionBounds);

    canvas.drawArc(oval, extension, flexion - extension, true, arcPaint);
    canvas.drawLine(0.0f, extensionBounds.height(), oval.right / 2, extensionBounds.height(), linePaint);
    canvas.drawText(extensionString, extensionLabelX, extensionLabelY, textPaint);
    canvas.drawText(decimalFormat.format(flexion) + "˚", flexionLabelX, flexionLabelY, textPaint);
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    // Account for padding
    float xpad = (float)(getPaddingLeft() + getPaddingRight());
    float ypad = (float)(getPaddingTop() + getPaddingBottom());

    float ww = (float)w - xpad;
    float hh = (float)h - ypad;

    String extensionString = decimalFormat.format(extension) + "˚";
    textPaint.getTextBounds(extensionString, 0, extensionString.length(), extensionBounds);
    float diameter = Math.min(ww, (hh - extensionBounds.height()) * 2.0f) - extensionBounds.height();

    oval = new RectF(
            0,
            diameter / -2.0f,
            diameter,
            diameter / 2.0f);
    oval.offsetTo(getPaddingLeft(), getPaddingTop() - diameter / 2.0f + extensionBounds.height());
    flexionLabelY = diameter / 2.0f + extensionBounds.height();
    flexionLabelX = 0;
    extensionLabelY = extensionBounds.height();
    extensionLabelX = ww / 2;
}
}

你似乎找到了解决办法:你问题的最后一段。我不知道其他人是否做过类似的事情,在搜索了几个小时后也找不到任何东西,所以最后一段是问是否有人知道一个更好的图书馆,因为我无法让AChartEngine做我想做的事情。我最终创建了一个自定义视图,直到现在我还不知道你可以在Android中实现它。