I am trying to create chart like below:
While I've almost achieved everything by simply creating a line chart and customizing shape/paint for Renderer, I can't seem to find a way to fill the areas under the series line.
Any clues, how can I do this?
You could create your chart with a StackedXYAreaRenderer. Specify AREA_AND_SHAPES in the constructor and enable outlines. See the ChartFactory code for createStackedXYAreaChart() as an example.
StackedXYAreaRenderer r = new StackedXYAreaRenderer(XYAreaRenderer.AREA_AND_SHAPES);
r.setOutline(true);
Given a renderer, you can set the outline paint and stroke as desired.
Related
I see that I can use setLabelLinkPaint() to universally apply a color to all label links, but I'm looking to set each individual label link to a different color. Is there a way to do this?
It looks like for now the most straightforward way to approach this problem is to subclass the PiePlot class and override the drawRightLabel and drawLeftLabel methods. In my case, I needed to have the label link color match the corresponding pie chart section, so in my overridden methods I set g2.setPaint(getSectionPaint(record.getKey())).
My advice to anyone trying to do something similar is to watch out for casting errors if casting from a JFreeChart chart object. You will likely have to additionally subclass ChartFactory and modify it so that it uses your subclassed PiePlot and not the original one.
I need to create a chart like this picture bellow in Android.
and I am already aware of MPAndroidChart and AndroidHelloCharts libraries. but none of them are capable of drawing such thing.
do you know any way to create a chart like this?
please explain and at least suggest me some tutorials or articles that are related to what I am about to do.
thank you
Its actually pretty simple to create your own bar chart.
First you need to use drawRect to draw a rectangle.
And then drawText to draw text below the rectangle.
You may have noticed that both methods take a paint object as the parameter , you can think of the paint object like a brush. So you set the color to the brush and draw different elements.
I have written about it
here
This should be a quick question, but I was wondering how I would make the line color different from points in JFreeChart. I'm using an XYLineAndShapeRenderer and I make getItemPaint(int,int) custom to look at a List to determine the color of each point. However when I make it so that all the points are the same color in the beginning, it makes it so that the line is the same color as all the points (Color.GREEN), but I would like it to be blue (Color.BLUE).
Thank you in advance.
Edit: I noticed now that when I update a single point it change the line before it to be that color, which I don't want. How do I keep the line and point colors seperate?
By default the shapes are drawn using the seriesPaint, but there are two flags useFillPaint and useOutlinePaint that you can set to have the shapes filled and outlined with the colours defined for the fill and outline. There is some info in the Javadocs:
http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/renderer/xy/XYLineAndShapeRenderer.html
I created a line chart:
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:
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.
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.
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));
In my application, I am showing data in a table as well as through a Dual Axis Bar/Line JFreeChart. To save some space (as the charts are being saved as PNG and put on PDF with iText PDF), I wanted to take the Graphics from the Legend, use them in the tabular view, and remove the legend.
Is there a way to grab the icons that lie with the legend item? I have found the LegendGraphic class, which seemed like would be the method to retrieve the icon from the LegendItem, but have not found anything in the documentation for LegendItem that would indicate it does.
It would be preferable if they were returned in an object that could easily be used to create a com.itextpdf.text.Image, such as byte[] or java.awt.Image.
You can get a series' LegendItem using the chart renderer's getLegendItem() method. You can change a series' Shape using the methods of ShapeUtilities, as shown in this example. See also DefaultDrawingSupplier for details of how createStandardSeriesShapes() works.
Addendum: Note that the renderer's getLegendItem() method works even if you create the chart with no legend or later use chart.removeLegend(). Once you have the LegendItem, you can use it's attributes as required.
System.out.println(renderer.getLegendItem(0, 0).getShape());
System.out.println(renderer.getLegendItem(0, 0).getFillPaint());