Increase the length of line in legend in jfreechart - java

I am rendering a line chart using JFreechart. I need help to modify legend which is being rendered by the JFree. I need to increase the length of line in legend area. Below image shows the current output.
Below images shows what I want to achieve
Thanks

It can be done by using the code below:
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
renderer.setLegendLine(new Line2D.Double(-20.0D, 0.0D, 20.0D, 0.0D));

Related

JFreechart, Line Chart with filled Areas

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.

How to remove the section label boxes surrounding the section label in pie chart

Is it possible to remove the section label boxes from the below pie chart.I searched alot but was not able to get an answer.
![enter image description here]
[1] http://tinypic.com/view.php?pic=2vkhuyp&s=5
the above link is for pie chart drawn using java.I mean i dont want the percent shown inside the pie chart surrounded with a box it should just show the percent for ex.14%
PiePlot plot = (PiePlot) chart.getPlot();
plot.setLabelBackgroundPaint(null);
plot.setLabelOutlinePaint(null);
plot.setLabelShadowPaint(null);

JFreeChart with shadow and circle nodes

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));

Adding legend to jFreechart

I have come up with my final hysteresis plot, which looks like this:
My earlier post:
Plotting a hysteresis loop with jFreeChart
I have used 4 XYSeries for my first hysteresis loop and another four for the second hysteresis loop.
If i turn on the legend
JFreeChart chart = ChartFactory.createXYLineChart(
"Hysteresis Plot", // chart title
"Pounds(lb)", // domain axis label
"Movement(inch)", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);
it appears like this :
I just want to show that blue is my first hysteresis loop and red is my second hysteresis loop, which I have added as subtitle in the first pic as workaround. Can someone guide how I can add manual legends which indicate blue as first loop and red as second.
Thanks
Because ChartFactory.createXYLineChart() creates an XYPlot, you could try setFixedLegendItems(), mentioned here and here.
A more ambitious scheme is to suppress the native legend and render the legend items in a separate component, as shown here.

How to specify the position and layout of a JFreeChart chart legend

I am using JFreeChart to render a stacked area chart. By default, the chart legend is rendered below the plot with the elements laid out horizontally. I would like the legend to appear on the right of the plot with the elements laid out as a vertical list.
Is this possible and, if so, how do I do it?
A little more time examining the API would have given me the answer:
LegendTitle legend = chart.getLegend();
legend.setPosition(RectangleEdge.RIGHT);
Here is the equivalent for older versions:
StandardLegend legend = new StandardLegend();
legend.setPreferredWidth(100);
legend.setAnchor(Legend.EAST);
jfreechart.setLegend(legend);

Categories

Resources