AndroidPlot:域标签从1到11 [英] AndroidPlot: domain labels from 1 to 11

查看:67
本文介绍了AndroidPlot:域标签从1到11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的应用程序中实现了AndroidPlot,除了X轴标签(它们从0到10)外,它都可以正常工作.我想显示1到11.此外,Y轴上的标签没有出现.

I've implemented AndroidPlot in my app and it works fine, apart from the X-axis labels, which they go from 0 to ten. I'd like to display 1 to eleven. Besides, the labels on the Y-axis do not appear.

我正在使用的代码:

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);

        }...

推荐答案

您可以应用自定义格式程序以使标签打印任何内容.对于您而言,我相信这样的方法应该可以工作:

You can apply a custom formatter to make the labels print whatever you want. In your case, I believe something like this should work:

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;}
});

这篇关于AndroidPlot:域标签从1到11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆