【问题标题】:AndroidPlot: domain labels from 1 to 11AndroidPlot:从 1 到 11 的域标签
【发布时间】:2013-04-10 01:06:40
【问题描述】:

我已经在我的应用程序中实现了 AndroidPlot,它工作正常,除了 X 轴标签,它们从 0 到 10。我想显示 1 到 11。此外,不会出现 Y 轴上的标签。

我正在使用的代码:

import java.text.DecimalFormat;
import java.util.Arrays;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import com.androidplot.series.XYSeries;
import com.androidplot.xy.LineAndPointFormatter;
import com.androidplot.xy.SimpleXYSeries;
import com.androidplot.xy.XYPlot;
import com.androidplot.xy.XYStepMode;

public class Scatter extends Activity {
    private XYPlot mySimpleXYPlot;

    //declare new arrays

   float[] one;
   float[] two;
   float[] three;
   Number[] series1Numbers; 
   Number[] series2Numbers;
   Number[] series3Numbers;
   String chainringCount;


    /** Called when the activity is first created. */
    @SuppressWarnings("deprecation")

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.scatter);


        Bundle bundle = this.getIntent().getExtras();
        one = bundle.getFloatArray("one");
        two = bundle.getFloatArray("two");
        three = bundle.getFloatArray("three");
        chainringCount=bundle.getString("CC");



        if (Integer.parseInt(chainringCount)==1){
            series1Numbers = new Number[one.length];

            for (int a=0; a<one.length; a++){
                series1Numbers[a]=one[a];
            }

            mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
            mySimpleXYPlot.setDomainStep(XYStepMode.SUBDIVIDE,11);
            mySimpleXYPlot.setDomainStep(XYStepMode.INCREMENT_BY_VAL,1);
            mySimpleXYPlot.setDomainValueFormat(new DecimalFormat("#"));
            mySimpleXYPlot.setTicksPerRangeLabel(13);
            mySimpleXYPlot.disableAllMarkup();
            mySimpleXYPlot.getBackgroundPaint().setAlpha(0);
            mySimpleXYPlot.getGraphWidget().getBackgroundPaint().setAlpha(0);
            mySimpleXYPlot.getGraphWidget().getGridBackgroundPaint().setAlpha(0);
            mySimpleXYPlot.setDomainLabel(getString(R.string.domainName));
            mySimpleXYPlot.setRangeLabel(getString(R.string.rangeName));

            XYSeries series1 = new SimpleXYSeries(Arrays.asList(series1Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "#1"); 
            LineAndPointFormatter series1Format = new LineAndPointFormatter(Color.rgb(0, 200, 0), Color.rgb(0, 100, 0),null);                                  // fill color (none)
            mySimpleXYPlot.addSeries(series1, series1Format);

        }...

【问题讨论】:

    标签: android axis-labels androidplot


    【解决方案1】:

    您可以应用自定义格式化程序以使标签打印您想要的任何内容。在你的情况下,我相信这样的事情应该有效:

    plot.setDomainValueFormat(new NumberFormat() {
    
                @Override
                public StringBuffer format(double d, StringBuffer sb, FieldPosition fp) {
                    return sb.append((d + 1) + ""); // shortcut to convert d+1 into a String
                }
    
                // unused
                @Override
                public StringBuffer format(long l, StringBuffer stringBuffer, FieldPosition fieldPosition) { return null;}
    
                // unused
                @Override
                public Number parse(String s, ParsePosition parsePosition) { return null;}
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-19
      • 2011-10-10
      • 1970-01-01
      相关资源
      最近更新 更多