将点形状添加到afreechart

时间:2013-11-15 20:42:34

标签: android jfreechart shapes timeserieschart

我尝试过无数组合,但无法获得下面两个数据集中的第一个以显示点形状(正方形,圆形等等)。代码如下所示:

final AFreeChart chart = ChartFactory.createTimeSeriesChart("","","",dataset,false,false,false);

chart.setBackgroundPaintType( new SolidColor( Color.BLACK ) );

final XYDataset dataset2 = MovingAverage.createMovingAverage(dataset,"Over a week",7 * 24 * 60 * 60 * 1000L,0L);

final XYPlot plot = (XYPlot) chart.getPlot();

plot.setDataset( 1, dataset2 );

plot.setBackgroundPaintType( new SolidColor( Color.BLACK ) );

plot.setDomainGridlinesVisible( true );
plot.setDomainGridlinePaintType( new SolidColor( Color.GRAY ) );
plot.setRangeGridlinesVisible( true );
plot.setRangeGridlinePaintType( new SolidColor( Color.GRAY ) );

final ValueAxis valueAxis = plot.getDomainAxis();

valueAxis.setTickLabelPaintType( new SolidColor( Color.WHITE ) );
valueAxis.setTickLabelFont( new Font( "Dialog", Typeface.NORMAL, 20 ) );

final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

rangeAxis.setTickLabelPaintType( new SolidColor( Color.WHITE ) );
rangeAxis.setTickLabelFont( new Font( "Dialog", Typeface.NORMAL, 20 ) );

rangeAxis.setRange( m_dMin, m_dMax );

final StandardXYItemRenderer renderer0 = new StandardXYItemRenderer( StandardXYItemRenderer.SHAPES_AND_LINES );
final XYSplineRenderer renderer1 = new XYSplineRenderer();

plot.setRenderer( 0, renderer0 );
plot.setRenderer( 1, renderer1 );

renderer0.setSeriesPaintType( 0, new SolidColor( Color.YELLOW ) );
renderer0.setSeriesStroke( 0, (float) 2.0 );

renderer1.setSeriesPaintType( 0, new SolidColor( Color.GREEN ) );
renderer1.setSeriesStroke( 0, (float) 2.0 );

我已经成功应用了一些自定义设置(例如每个系列的线条颜色和粗细),但形状让我不知所措。

此外,关于afreechart上的教程,示例等似乎几乎没有任何内容。 stackoverflow上甚至没有afreechart标签。你们怎么去探索这个图书馆?对我来说,每一步都像根管。

谢谢大家。

2 个答案:

答案 0 :(得分:0)

您可以使用setBaseShape方法更改形状。

final XYLineAndShapeRenderer lineAndShapeRenderer = new XYLineAndShapeRenderer();
lineAndShapeRenderer.setSeriesShape(0, new RoundRectShape(-6, -6, 12, 12, 6, 6));

Example of Shape

答案 1 :(得分:0)

XYSeriesRenderer incomeRenderer = new XYSeriesRenderer(); 
incomeRenderer.setPointStyle(PointStyle.CIRCLE);

我正在使用achartengine-1.2.0.jar。