JFreeChart with shadow and circle nodes

2019-09-02 13:49发布

I created a line chart:

enter image description here

But I want it to make it looks like this. I also don't know what kind of chart is this. I want to make also have a shadow and circle nodes in it. Just like this:

enter image description here

How can I do this? By the way I'm displaying the chart in the webpage as PNG image format if it is relevant to my question. Thanks in advance.

2条回答
Viruses.
2楼-- · 2019-09-02 14:11

For info, the sample chart you are trying to replicate is included in the JFreeChart demo collection. The complete source code for the demos is included with the JFreeChart Developer Guide. You could save yourself some time and your company some money by asking them to buy the JFreeChart Developer Guide, it's not so expensive. On to the answer...

The shadow effect you are looking for can be added to any CategoryPlot or XYPlot by setting the shadow generator:

plot.setShadowGenerator(new DefaultShadowGenerator());

It looks nice, but be aware that it requires rendering the chart as a bitmap so it won't play so nicely if you are exporting your charts to SVG or PDF or other vector formats.

The shapes on the lines can be added by changing attributes on the renderer you are using (LineAndShapeRenderer in this case).

LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setBaseShapesVisible(true);

The setBaseShapesVisible() method sets the default (or 'base') flag value for all series. You can override that default on a per-series basis if you want to. You may also want to tweak the colors being used...by default all the shapes are drawn and filled using the series color, but there are flags that can be set to make the renderer use the series fill and series outline colors (which is done in the example to get the white fill in the shapes).

The JFreeChart renderers are very configurable, so I suggest you spend some time looking through the API documentation to see what is possible.

查看更多
放荡不羁爱自由
3楼-- · 2019-09-02 14:21

Here's your solution:

    LineAndShapeRenderer renderer
            = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseFillPaint(Color.white);
    renderer.setSeriesStroke(0, new BasicStroke(3.0f));
    renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
    renderer.setSeriesShape(0, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0));
查看更多
登录 后发表回答