androidplot中的奇怪行

时间:2013-12-14 16:20:52

标签: android bar-chart androidplot

我正在创建我的androidplot条形图,但我在域轴的起点有奇怪的行问题。你可以在屏幕上看到它

enter image description here

如何删除它?这是我的代码:

布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <com.androidplot.xy.XYPlot
            android:id="@+id/barPlot"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            androidPlot.titleWidget.labelPaint.textSize="@dimen/title_font_size"
            androidPlot.rangeLabelWidget.labelPaint.textSize="@dimen/range_label_font_size"
            androidPlot.graphWidget.marginTop="5dp"
            androidPlot.graphWidget.marginLeft="35dp"
            androidPlot.graphWidget.marginBottom="5dp"
            androidPlot.graphWidget.marginRight="5dp"
            androidPlot.graphWidget.gridBackgroundPaint.color="#FFFFFF"
            androidPlot.graphWidget.rangeLabelPaint.textSize="@dimen/range_tick_label_font_size"
            android:layout_weight="1"
            androidPlot.graphWidget.gridLinePaint.color="#000000"/>

</LinearLayout>

代码:

package com.brokenheart.alcotest.activities;

import java.text.FieldPosition;
import java.text.Format;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.PointF;
import android.os.Bundle;

import com.androidplot.ui.SeriesRenderer;
import com.androidplot.xy.BarFormatter;
import com.androidplot.xy.BarRenderer;
import com.androidplot.xy.BoundaryMode;
import com.androidplot.xy.SimpleXYSeries;
import com.androidplot.xy.XYPlot;
import com.androidplot.xy.XYSeries;
import com.androidplot.xy.XYStepMode;
import com.androidplot.xy.SimpleXYSeries.ArrayFormat;
import com.brokenheart.alcotest.R;
import com.brokenheart.alcotest.database.entities.Measure;

public class ChartActivity extends Activity 
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chart);

        List<Number> values = new ArrayList<Number>();
        ArrayList<Measure> measures = getIntent().getParcelableArrayListExtra(getString(R.string.constant_measures_intent_tag));
        for(Measure measure : measures) {
            values.add(measure.getThreshold().getValue());
        }

        SimpleXYSeries series = new SimpleXYSeries(values,ArrayFormat.Y_VALS_ONLY,"");
        MyBarFormatter barFormatter = new MyBarFormatter(Color.argb(200, 100, 150, 100), Color.LTGRAY);

        XYPlot plot = (XYPlot)findViewById(R.id.barPlot);
        plot.addSeries(series, barFormatter);

        plot.getGraphWidget().setGridPadding(30, 10, 30, 0);
        plot.getLegendWidget().setVisible(false);

        plot.setRangeStep(XYStepMode.INCREMENT_BY_VAL, 1);
        plot.getGraphWidget().setRangeLabelOrientation(-45);
        plot.setRangeLowerBoundary(0, BoundaryMode.FIXED);
        plot.setRangeTopMin(11);
        plot.setRangeValueFormat(new RangeFormatter());

        MyBarRenderer renderer = ((MyBarRenderer)plot.getRenderer(MyBarRenderer.class));
        renderer.setBarWidthStyle(BarRenderer.BarWidthStyle.FIXED_WIDTH);
        renderer.setBarWidth(10);  

        plot.setDomainBoundaries(-1,1, BoundaryMode.FIXED);
        plot.getGraphWidget().getDomainSubGridLinePaint().setColor(Color.TRANSPARENT);
        plot.getGraphWidget().getDomainGridLinePaint().setColor(Color.TRANSPARENT);

        plot.getGraphWidget().getDomainLabelPaint().setColor(Color.TRANSPARENT);
        plot.getGraphWidget().getDomainOriginLabelPaint().setColor(Color.TRANSPARENT);

        plot.redraw();
    }

    class MyBarFormatter extends BarFormatter {
        public MyBarFormatter(int fillColor, int borderColor) {
            super(fillColor, borderColor);
        }

        @Override
        public Class<? extends SeriesRenderer> getRendererClass() {
            return MyBarRenderer.class;
        }

        @Override
        public SeriesRenderer getRendererInstance(XYPlot plot) {
            return new MyBarRenderer(plot);
        }
    }

    class MyBarRenderer extends BarRenderer<MyBarFormatter> {

        public MyBarRenderer(XYPlot plot) {
            super(plot);
        }

        /**
         * Implementing this method to allow us to inject our
         * special selection formatter.
         * @param index index of the point being rendered.
         * @param series XYSeries to which the point being rendered belongs.
         * @return
         */
        //@Override
        // TODO: figure out why using @Override screws up the Maven builds
        protected MyBarFormatter getFormatter(int index, XYSeries series) { 
            return getFormatter(series);
        }
    }

    //FIXME: nie da sie ustawić enuma
    private class RangeFormatter extends Format { 
        private static final long serialVersionUID = 1L;

        @Override
        public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
            Number num = (Number) obj;
            switch(num.intValue()) {
                case 1:
                    toAppendTo.append(getString(R.string.a));
                    break;
                case 2:
                    toAppendTo.append(getString(R.string.c));
                    break;
                case 3:
                    toAppendTo.append(getString(R.string.f));
                    break;
                case 4:
                    toAppendTo.append(getString(R.string.h));
                    break;
                case 5:
                    toAppendTo.append(getString(R.string.r));
                    break;
                case 6:
                    toAppendTo.append(getString(R.string.c));
                    break;
                case 7:
                    toAppendTo.append(getString(R.string.b));
                    break;
                case 8:
                    toAppendTo.append(getString(R.string.e));
                    break;
                case 9:
                    toAppendTo.append(getString(R.string.y));
                    break;
                case 10:
                    toAppendTo.append(getString(R.string.v));
                    break;
                default:
                    toAppendTo.append(getString(R.string.3));
                    break;
            }
            return toAppendTo;
        }

        @Override
        public Object parseObject(String source, ParsePosition pos) {
            return null;
        }
    }
}

1 个答案:

答案 0 :(得分:1)

这是因为

plot.getGraphWidget().setGridPadding(30, 10, 30, 0);

如果将它删除,它将会消失。实际上这是移动的图形网格线。