我正在尝试在Android中的烛台图表中添加轴断点。 添加或不添加轴断点由基础数据决定。
在第一张图片上,您可以看到没有轴断裂的正常图表状态。请在左上角提及注释:
在第二张图片上,您可以看到带有轴断点的图表。从图中可以看出,存在一些问题:
蜡烛的一半隐藏在轴断线的后面。如何防止这种重叠?
注意注释的位置:它显示在错误的位置并且具有奇怪的角度!
另请注意第3轴断裂,它也显示不正确。
任何人都可以建议如何解决所描述的问题吗?
答案 0 :(得分:1)
- 蜡烛的一半隐藏在轴线的后面。怎么样 我可以防止这种重叠吗?
醇>
您可以为轴断点StartValue和EndValue添加一些余量。
- 注意注释的位置:它显示在错误的位置并且有奇怪的角度!
醇>
我无法使用下面的示例代码重现这一点 你能否提出一个简单的示例项目来改进你的问题,我们可以按原样运行这个项目来重现这个问题吗?
- 另请注意第3轴断裂,它也显示不正确。
醇>
我可以看到一个额外的轴断点被绘制,类似于图像中的那个,倾斜和图表的中间。但是,我只能使用评估版本重现此问题,而不能使用注册版本(ID1078)重现此问题 我认为它与" EVALUATION VERSION"我们正在绘制图表中间的斜水印。
以下是我使用的代码:
tChart1.getAspect().setView3D(false);
tChart1.getLegend().setVisible(false);
Candle candle1 = new Candle(tChart1.getChart());
candle1.fillSampleValues(80);
DateTime dt = DateTime.getNow();
for (int i = 0; i < candle1.getCount(); i++) {
candle1.getXValues().setValue(i, dt.toDouble());
dt.add(Calendar.MINUTE, 1);
}
//tChart1.getAxes().getBottom().setIncrement(DateTimeStep.FIVEMINUTES);
tChart1.getAxes().getBottom().getLabels().setDateTimeFormat("hh:mm");
AxisBreaksTool axisBreaksTool1 = new AxisBreaksTool(tChart1.getAxes().getBottom());
for (int i=0; i<3; i++) {
AxisBreak axisBreak1 = new AxisBreak(axisBreaksTool1);
axisBreak1.setStartValue(candle1.getXValues().getValue(10*(i+1))-0.6);
axisBreak1.setEndValue(candle1.getXValues().getValue(10*(i+1)+5)+0.6);
axisBreak1.setStyle(AxisBreakStyle.LINE);
axisBreaksTool1.getBreaks().add(axisBreak1);
}
Annotation annotation1 = new Annotation(tChart1.getChart());
annotation1.setText("My Text");
annotation1.setLeft(10);
annotation1.setTop(10);
与Annotation工具和AxisBreaksTool似乎存在冲突:只要我添加轴断点,注释就会消失(ID1077)。
修改强>
如果您希望您的轴Breaks StartValue和EndValue取决于CandleWidth,您可以以轴为单位计算蜡烛宽度的大小,但您需要绘制图表来执行此操作。
以下是如何使用ChartPaintListener计算底轴单位的CandleWidth并将其用作AxisBreaks的额外边距:
tChart1.addChartPaintListener(new ChartPaintAdapter() {
@Override
public void chartPainted(ChartDrawEvent e) {
Candle candle1 = (Candle)tChart1.getSeries(0);
double onePxWidth = tChart1.getAxes().getBottom().calcPosPoint(1) - tChart1.getAxes().getBottom().calcPosPoint(0);
double tmpWidthLeft = onePxWidth*(candle1.getCandleWidth()/2 + 4);
double tmpWidthRight = onePxWidth*(candle1.getCandleWidth()/2 + 3);
AxisBreaksTool axisBreaksTool1 = (AxisBreaksTool)tChart1.getTools().getTool(0);
for (int i=0; i<axisBreaksTool1.getBreaks().size(); i++) {
AxisBreak axisBreak1 = axisBreaksTool1.getBreaks().get(i);
axisBreak1.setStartValue(candle1.getXValues().getValue(10*(i+1))+tmpWidthLeft);
axisBreak1.setEndValue(candle1.getXValues().getValue(10*(i+1)+5)-tmpWidthRight);
}
}
});