给出以下代码:
chart = new Chart2D();
trace = new Trace2DSimple();
trace.setTracePainter(new TracePainterVerticalBar(chart));
chart.addTrace(trace);
// default tracepainter color is Black
TracePoint2D first = new TracePoint2D(0, 1 );
TracePoint2D second = new TracePoint2D(1, 10 );
TracePoint2D third = new TracePoint2D(2, 20 );
PointPainterVerticalBar red = new PointPainterVerticalBar(10,chart);
red.setColor(Color.red);
PointPainterVerticalBar green = new PointPainterVerticalBar(10,chart);
green.setColor(Color.green);
PointPainterVerticalBar blue = new PointPainterVerticalBar(10,chart);
blue.setColor(Color.blue);
first.addAdditionalPointPainter(red);
second.addAdditionalPointPainter(green);
third.addAdditionalPointPainter(blue);
trace.addPoint(first);
trace.addPoint(second);
trace.addPoint(third);
正如你所看到的那样,我试图在图表上获得三种不同颜色的TracePoints,但不知怎的,它们都保持黑色。任何想法?
答案 0 :(得分:1)
完全可以实现你自己的Trace-和PointPainter。 在新的TracePainter中,告诉它使用你的新PointPainter:
public TracePainterBlank(final int barWidth, final Chart2D chart) {
this.m_pointPainter = new PointPainterBlank(barWidth, chart);
}
然后在PointPainer中明确说明您使用tracepainter.setColor(Color.whatever)
设置的颜色并将其应用于实际图形:
public void paintPoint(final int absoluteX, final int absoluteY, final int nextX,
final int nextY, final Graphics g, final ITracePoint2D original) {
g.setColor(this.getColor());
g.fillRect(absoluteX - this.m_halfWidth, absoluteY, 2 * this.m_halfWidth, this.m_chart
.getYChartStart()
- absoluteY);
}
这使您可以单独为每个TracePoint着色。
答案 1 :(得分:0)
我认为使用jChart2D只能为“痕迹”设置颜色,而不能为各个点设置颜色。
答案 2 :(得分:0)
您的代码有问题,因为您只将颜色设置为红色三次。
但是因为你写的时候它仍然是黑色的,我担心会有一个错误(最近代码被改变了)。因此,如果是这种情况,请考虑在sourceforge上发布错误。
HTH, Achim的