Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8787785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:58:38+00:00 2026-06-13T21:58:38+00:00

The answer accepted here ( JFreechart(Java) – How to draw lines that is partially

  • 0

The answer accepted here (JFreechart(Java) – How to draw lines that is partially dashed lines and partially solid lines?) helped me start down the path of changing my seriesstroke lines on my chart. After stepping through my code and watching the changes, I see that my seriesstroke does in fact change to “dashedStroke” when it is supposed to (after a certain date “dashedAfter”), but when the chart is rendered the entire series line is dashed. How can I get a series line to be drawn solid at first and dashed after a set date?

/* series line modifications */
final Number dashedAfter = timeNowDate.getTime();

XYLineAndShapeRenderer render = new XYLineAndShapeRenderer() {
  Stroke regularStroke = new BasicStroke();
  Stroke dashedStroke = new BasicStroke(
                            1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                            1.0f, new float[] {10.0f, 6.0f}, 0.0f );
  @Override
  public Stroke getItemStroke(int row, int column) {
    Number xVal = cd.getXValue(row, column);
    if (xVal.doubleValue() > dashedAfter.doubleValue()) { 
      return dashedStroke; 
    } else { 
      return regularStroke; 
    }
  }
};
render.setBaseShapesVisible(false);
render.setBaseShapesFilled(true);
render.setDrawSeriesLineAsPath(true);
plot.setRenderer(render);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:58:39+00:00Added an answer on June 13, 2026 at 9:58 pm

    Have you tried implementing AbstractRenderer#getItemStroke?

    enter image description here

    In this example I’m using a dashed line for x > 4 for series 2:

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(){
        Stroke soild = new BasicStroke(2.0f);
        Stroke dashed =  new BasicStroke(1.0f,BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] {10.0f}, 0.0f);
        @Override
        public Stroke getItemStroke(int row, int column) {
    if (row == 2){
      double x = dataset.getXValue(row, column);
      if ( x > 4){
        return dashed;
      } else {
        return soild;
      } 
    } else
      return super.getItemStroke(row, column);
        }
      };
      renderer.setBaseShapesVisible(true);
      renderer.setBaseShapesFilled(true);
      renderer.setBaseStroke(new BasicStroke(3));
      plot.setRenderer(renderer);
    

    Although this example is using and XYSeries and not dates you shold be able to modify it for you needs.

    Here is the full example

    import java.awt.BasicStroke;
    import java.awt.Stroke;
    
    import javax.swing.JPanel;
    
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.plot.PlotOrientation;
    import org.jfree.chart.plot.XYPlot;
    import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
    import org.jfree.data.xy.XYDataset;
    import org.jfree.data.xy.XYSeries;
    import org.jfree.data.xy.XYSeriesCollection;
    import org.jfree.ui.ApplicationFrame;
    import org.jfree.ui.RefineryUtilities;
    
    public class LineChartDemo2 extends ApplicationFrame {
    
        public LineChartDemo2(String title) {
            super(title);
            JPanel chartPanel = createDemoPanel();
            chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
            setContentPane(chartPanel);
        }
    
        private static JFreeChart createChart(final XYDataset dataset) {
    
            JFreeChart chart = ChartFactory.createXYLineChart(
                "Line Chart Demo: XYLineAndShapeRenderer",     
                "X",                     
                "Y",                     
                dataset,              
                PlotOrientation.VERTICAL,
                false,                     
                false,                 
                false             
            );
    
            XYPlot plot = (XYPlot) chart.getPlot();
            plot.setDomainPannable(true);
            plot.setRangePannable(true);
    
            XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(){
                Stroke soild = new BasicStroke(2.0f);
                Stroke dashed =  new BasicStroke(1.0f,BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] {10.0f}, 0.0f);
                @Override
                public Stroke getItemStroke(int row, int column) {
                    if (row == 2){
                        double x = dataset.getXValue(row, column);
                        if ( x > 4){
                            return dashed;
                        } else {
                            return soild;
                        } 
                    } else
                        return super.getItemStroke(row, column);
                }
            };
    
            renderer.setBaseShapesVisible(true);
            renderer.setBaseShapesFilled(true);
            renderer.setBaseStroke(new BasicStroke(3));
            plot.setRenderer(renderer);
            return chart;
        }
    
        public static JPanel createDemoPanel() {
            JFreeChart chart = createChart(createDataset());
            ChartPanel panel = new ChartPanel(chart);
            panel.setMouseWheelEnabled(true);
            return panel;
        }
    
        public static void main(String[] args) {
            LineChartDemo2 demo = new LineChartDemo2(
                    "JFreeChart");
            demo.pack();
            RefineryUtilities.centerFrameOnScreen(demo);
            demo.setVisible(true);
        }
    
        private static XYDataset createDataset() {
    
            XYSeries series1 = new XYSeries("First");
            series1.add(1.0, 1.0);
            series1.add(2.0, 4.0);
            series1.add(3.0, 3.0);
            series1.add(4.0, 5.0);
            series1.add(5.0, 5.0);
            series1.add(6.0, 7.0);
            series1.add(7.0, 7.0);
            series1.add(8.0, 8.0);
    
            XYSeries series2 = new XYSeries("Second");
            series2.add(1.0, 5.0);
            series2.add(2.0, 7.0);
            series2.add(3.0, 6.0);
            series2.add(4.0, 8.0);
            series2.add(5.0, 4.0);
            series2.add(6.0, 4.0);
            series2.add(7.0, 2.0);
            series2.add(8.0, 1.0);
    
            XYSeries series3 = new XYSeries("Third");
            series3.add(3.0, 4.0);
            series3.add(4.0, 3.0);
            series3.add(5.0, 2.0);
            series3.add(6.0, 3.0);
            series3.add(7.0, 6.0);
            series3.add(8.0, 3.0);
            series3.add(9.0, 4.0);
            series3.add(10.0, 3.0);
    
            XYSeriesCollection dataset = new XYSeriesCollection();
            dataset.addSeries(series1);
            dataset.addSeries(series2);
            dataset.addSeries(series3);
    
            return dataset;
    
        }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote code below that is very similar to the accepted answer here .
In light of the accepted answer pointing out that returning a non-const reference to
UPDATE: Here's my solution (inspired by accepted answer): function log(msg, values) { if(config.log ==
This question here is about creating an authentication scheme. The accepted answer given by
The generally accepted answer is that you can't. However there is mounting evidence that
According to MSDN here and here (as well as the accepted answer to this
Can you give me a good start for this? Thanks! Edit: The accepted answer
I'm using the method from the accepted answer here to construct a gameloop thread.
This question refers to this one along with its accepted answer posted here on
Using the accepted answer (with the doctests) for the Memoized decorator from here: What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.