Tuesday, May 14, 2013

Jfreechart - Change line stye

This would make your second series show as a dashed line:
plot.getRenderer().setSeriesStroke(
    1, 
    new BasicStroke(
        2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
        1.0f, new float[] {6.0f, 6.0f}, 0.0f
    )
 

Override the getItemStroke() method in AbstractRenderer.
     final BasicStroke dashedStroke = new BasicStroke(
                  2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                  1.0f, new float[] {6.0f, 6.0f}, 0.0f);
     XYLineAndShapeRenderer render = new XYLineAndShapeRenderer() {
        @Override
        public Stroke getItemStroke(int row, int column) {
            if (column < dashedThreshold) {
                return lookupSeriesStroke(row);
            } else {
               return dashedStroke;
            }
       };
 
Reference:
http://stackoverflow.com/questions/7797353/jfreechartjava-how-to-draw-lines-that-is-partially-dashed-lines-and-partiall 

Related Posts:

  • Jfreechart - Tips Set a FormatOverride on the axis for NumberAxis and a DateAxis   XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setNumberFormatOverride( new NumberFormat(){ … Read More
  • Jfreechart - Change line styeThis would make your second series show as a dashed line: plot.getRenderer().setSeriesStroke( 1, new BasicStroke( 2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] {6.0f, 6.0f}, 0… Read More
  • Jfreechart - Change Shape PointDiamon/Cross/Triangle Shape renderer.setSeriesShape(seriesIndex,ShapeUtilities.createDiamond(5)); renderer.setSeriesShape(seriesIndex,ShapeUtilities.createDiagonalCross(5,5)); .... Circle Shape circle  = new Ellipse2D.… Read More
  • Jfreechart - XYSplineRenderer        XYSeriesCollection  dataset = new XYSeriesCollection();         JFreeChart chart = ChartFactory.createXYLineChart(         &nbs… Read More

0 comments:

Post a Comment