我已经在我的应用程序中实现了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);
}...
答案 0 :(得分:2)
您可以应用自定义格式化程序,使标签可以随意打印。在你的情况下,我相信这样的事情应该有效:
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;}
});