List of usage examples for org.jfree.chart LegendItem setLineStroke
public void setLineStroke(Stroke stroke)
From source file:gavisualizer.LineChart.java
@Override public void generate() { // Creates Line Chart from variables JFreeChart chart = ChartFactory.createLineChart(_title, // chart title _axisLabelDomain, // domain axis label _axisLabelRange, // range axis label _dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend false, // tooltips false // urls );// w w w.j a va 2s. c o m // Set the Plot to certain colors final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); plot.setOutlinePaint(Color.white); // Set Legend to the right of the chart final LegendTitle lt = (LegendTitle) chart.getLegend(); lt.setPosition(RectangleEdge.RIGHT); // Set paints for lines in the chart LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); DefaultDrawingSupplier dw = new DefaultDrawingSupplier(PAINTS, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE); plot.setDrawingSupplier(dw); // Customize stroke width of the series ((AbstractRenderer) renderer).setAutoPopulateSeriesStroke(false); renderer.setBaseStroke(STROKE_WIDTH); renderer.setBaseShapesVisible(false); // Include dashed lines if necessary List<String> rows = _dataset.getRowKeys(); // See if the title includes Downloads (Dashed lines are for Download lines) if (rows.get(rows.size() - 1).endsWith("Downloads")) { // Set the start to half the rows int start = _dataset.getRowCount() / 2; // Create an initial value int init = 0; // Iterate through the Download lines while (start < _dataset.getRowCount()) { // Make sure series and legend have dashes renderer.setSeriesStroke(start, DASHED_STROKE); LegendItemCollection legend = renderer.getLegendItems(); LegendItem li = legend.get(start - 1); li.setLineStroke(DASHED_STROKE); // Make sure the color matches the undashed year renderer.setSeriesPaint(start, renderer.getItemPaint(init, 0)); init++; start++; } } // Customise the range axis... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); _chart = chart; }