我正在使用Graph View library在Android中绘制图形。我想画一张听力图。有谁知道如何使Y轴向下增长,并将水平标题设置在图形上方?
发布于 2015-03-02 21:28:17
第一部分相对简单;首先通过模拟现有的库逻辑创建您自己的Y标签集,但是将值以相反的顺序存储到您自己的字符串数组中。然后简单地将所有的Y值乘以-1,使它们为负,并设置图形视图以使用您自己的标签来掩盖它们的负性,例如。
Double yMin = Math.floor(...);
Double yMax = Math.ceil(...);
int yLabelsCnt = 1 + (int)(Math.ceil(yMaxValue) - yMin.intValue());
int yLabelInterval = (int)(Math.ceil((double)yLabelsCnt / MAX_Y_LABELS));
yLabelsCnt = (yLabelInterval > 1)
? (int)Math.ceil(yLabelsCnt / yLabelInterval)
: yLabelsCnt;
// Y labels
String[] yArray = new String[ yLabelsCnt ];
int j=yLabelsCnt-1;
for(int i = yMin.intValue(); i < (yMin.intValue() + (yLabelInterval * yLabelsCnt)); i+=yLabelInterval){
yArray[j--]=i.toString();
}
....
// invert the Y values
for (DataObjects myObject : myDataObjects) {
lineGraphSeries.appendData( new DataPoint(myObject.getValueX(), (myObject.getValueY() * -1.0 )),
true,
MAX_DATA_POINTS);
}
....
staticLabelsFormatter.setVerticalLabels(yArray);
graphView.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);https://stackoverflow.com/questions/28757201
复制相似问题