gpt4 book ai didi

Android 在 x 角度上绘制固定值

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:39:04 24 4
gpt4 key购买 nike

是否可以创建具有固定 x 和 y 值的图表?我的 x 值类似于 60、90、120、180、250、375、500、750、1000,但 androidplot 根据值之间的相等距离​​创建了 9 个不同的值。

Number[] timestamps = {60, 90, 120, 180, 250, 375, 500, 750, 1000};

我正在使用 mySimpleXYPlot.setDomainStep(XYStepMode.SUBDIVIDE, 9);我想解决方案是围绕这个命令,但我不知道该怎么做。

enter image description here

完整代码:

mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
Number[] numSightings = {70, 63, 56, 49, 43, 37, 32, 27, 23};

Number[] timestamps = {
60, 90, 120, 180, 250, 375, 500, 750, 1000

};

// create our series from our array of nums:
XYSeries series2 = new SimpleXYSeries(
Arrays.asList(timestamps),
Arrays.asList(numSightings),
"USA");


mySimpleXYPlot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);
mySimpleXYPlot.getGraphWidget().getGridLinePaint().setColor(Color.BLACK);
mySimpleXYPlot.getGraphWidget().getGridLinePaint().setPathEffect(new DashPathEffect(new float[]{1,1}, 1));
mySimpleXYPlot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK);
mySimpleXYPlot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK);

mySimpleXYPlot.setBorderStyle(Plot.BorderStyle.SQUARE, null, null);
mySimpleXYPlot.getBorderPaint().setStrokeWidth(1);
mySimpleXYPlot.getBorderPaint().setAntiAlias(false);
mySimpleXYPlot.getBorderPaint().setColor(Color.WHITE);

// Create a formatter to use for drawing a series using LineAndPointRenderer:
LineAndPointFormatter series1Format = new LineAndPointFormatter(
Color.rgb(0, 100, 0), // line color
Color.rgb(0, 100, 0), // point color
Color.rgb(100, 200, 0)); // fill color


// setup our line fill paint to be a slightly transparent gradient:
Paint lineFill = new Paint();
lineFill.setAlpha(200);
lineFill.setShader(new LinearGradient(0, 0, 0, 250, Color.WHITE, Color.GREEN, Shader.TileMode.MIRROR));

LineAndPointFormatter formatter = new LineAndPointFormatter(Color.rgb(0, 0,0), Color.BLUE, Color.RED);
formatter.setFillPaint(lineFill);
mySimpleXYPlot.getGraphWidget().setPaddingRight(2);
mySimpleXYPlot.addSeries(series2, formatter);

// draw a domain tick for each year:
mySimpleXYPlot.setDomainStep(XYStepMode.SUBDIVIDE, 9);
mySimpleXYPlot.setRangeBoundaries(-20,100, BoundaryMode.FIXED);

// customize our domain/range labels
mySimpleXYPlot.setDomainLabel("Frequency (Hz)");
mySimpleXYPlot.setRangeLabel("Loud pressure (dB)");
mySimpleXYPlot.getLegendWidget().setVisible(false);

// get rid of decimal points in our range labels:
mySimpleXYPlot.setRangeValueFormat(new DecimalFormat("0"));

//mySimpleXYPlot.setDomainValueFormat(new MyDateFormat());

// by default, AndroidPlot displays developer guides to aid in laying out your plot.
// To get rid of them call disableAllMarkup():
mySimpleXYPlot.disableAllMarkup();

最佳答案

XYStepType.INCREMENT_BY_VALUE

此模式为原点上方和下方的每个值的倍数创建一个刻度。让我们修改快速入门示例如下:

mySimpleXYPlot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 1);

这会告诉 XYPlot 为每个可见域值 (x) 绘制一个刻度,其中 x 减去 domainOrigin 的模数为零,或者更简单地说,从 domainOrigin 开始在每个增量 1 绘制一个刻度。现在,我们的情节现在看起来像这样:

enter image description here

来自 androidplot reference

关于Android 在 x 角度上绘制固定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10768100/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com