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

  • SEARCH
  • Home
  • 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 9131947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:13:39+00:00 2026-06-17T08:13:39+00:00

I have created a JFreeChart with the code below, but the Y-Axis marks are

  • 0

I have created a JFreeChart with the code below, but the Y-Axis marks are truncated. How should I display the chart even though the data points are overlapped in the Y-Axis?
Basically, I want the Y-Axis points to be generated from my file, a proper range is populated and displayed in the chart.

private static JFreeChart buildChart(TimeSeriesCollection dataset,
    String title, boolean endPoints) throws IOException {

// Create the chart

    JFreeChart chart0 = ChartFactory.createTimeSeriesChart(
        title, "Hour", "Count", dataset, true, true, false);

// Setup the appearance of the chart
    chart0.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) chart0.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(10.0, 10.0, 10.0, 10.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

// Display data points or just the lines?

    if (endPoints) {
        XYItemRenderer renderer = plot.getRenderer();
        if (renderer instanceof StandardXYItemRenderer) {
            StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;

            rr.setBaseShapesVisible(true);
            rr.setBaseShapesFilled(true);
            rr.setDrawSeriesLineAsPath(true);
            rr.setSeriesPaint(0, Color.blue.brighter());
            rr.setSeriesVisible(0, true); // default
            rr.setSeriesVisibleInLegend(0, true);  // default

            NumberAxis domainAxis = new NumberAxis();
            domainAxis.setUpperMargin(0.15);
            domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            domainAxis = (NumberAxis) plot.getDomainAxis();
            domainAxis = (NumberAxis) plot.getRangeAxis();
            domainAxis.setAutoRangeIncludesZero(false);
        }
    }

 // Tell the chart how we would like dates to read
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setAutoRange(true);

 //axis.getDefaultAutoRange();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));

    try {

        ChartUtilities.saveChartAsJPEG(new File("suc.jpg"), 1.0f, chart0, 990, 700);
    } catch (IOException e) {
        e.printStackTrace();
    }

    return chart0;
}

Below is the image that is created, clearly you can see that the Y-Axis there is an overlap showing.

enter image description here

  • 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-17T08:13:40+00:00Added an answer on June 17, 2026 at 8:13 am

    This is my current approach on the chart how data is being rendered…

    private static JFreeChart buildChart(TimeSeriesCollection dataset,
        String title, boolean endPoints) throws IOException {
    // Create the chart
        JFreeChart chart0 = ChartFactory.createTimeSeriesChart(
            title,
            "Hour", "Count",
            dataset,
            true,
            true,
            false);
    
    // Setup the appearance of the chart
    
        chart0.setBackgroundPaint(Color.white);
        XYPlot plot = (XYPlot) chart0.getXYPlot();
        plot.getDomainAxis().setAutoRange(true);
        plot.getRangeAxis().setRange(1.0, SucMaxi);
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);
        plot.getAxisOffset();
        plot.setAxisOffset(new RectangleInsets(10.0, 10.0, 10.0, 10.0));
        plot.setDomainCrosshairVisible(true);
        plot.setRangeCrosshairVisible(true);
    
    // Display data points or just the lines?
    
        if (endPoints) {
            XYItemRenderer renderer = plot.getRenderer();
            if (renderer instanceof StandardXYItemRenderer) {
                StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
                rr.setBaseShapesVisible(true);
                rr.setBaseShapesFilled(true);
                rr.setDrawSeriesLineAsPath(true);
                rr.setSeriesPaint(0, Color.blue.brighter());
                rr.setSeriesVisible(0, true); // default
                rr.setSeriesVisibleInLegend(0, true);  // default      
            }
        }
    
    // Tell the chart how we would like dates to read
    
        DateAxis axis = (DateAxis) plot.getDomainAxis();
    
    // Tick the X Axis by unit tick 1 hour
        axis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1));
        axis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
    
        try {
            ChartUtilities.saveChartAsJPEG(
                new File("suc.jpg"), 1.0f, chart0, 1000, 700);
        } catch (IOException e) {
            e.printStackTrace();
        }
    
        return chart0;
    }
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display a jfreechart chart in a jsp page. I have written
I have created a chart using JFreeChart inside a JSP. I want to render
I have a PDF which displays a dynamic image (Chart created with JFreeChart). The
I have heard of JfreeChart but is there any general steps for using data
I have a chart created as shown below, and I am adding values to
I have created a pie chart in JFreeChart. However, numerical values are not appearing
I have been using jfreechart to create Gantt chart and even managed to add
I have created two imageViews promatically as shown below: public void createImageViews(Integer count){ ImageView[]
I have created a servlet to handle the save of a JFreeChart displayed in
I have created an xml file like below <Engagements> <User name =jjjj> <Engagement id=1111/>

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.