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 740621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:32:15+00:00 2026-05-14T08:32:15+00:00

I am new to using JFreeChart and I’m sure there is a simple solution

  • 0

I am new to using JFreeChart and I’m sure there is a simple solution to my problem . .

PROBLEM:
I have a chart that shows multiple “events types” along the date X axis. The Y axis shows the “event category”. My problem is that only the latest date of an event type is shown for each category.

In the example below The chart shows data points for Event Type 1 at June 20th(Category 1) and at June 10th (Category 2). I had also added a data point for June 10th, Category 1 but the June 20th point erases it.

I think I am misunderstanding how the CategoryPlot is working. Am I using the wrong type of chart? I thought a scatter chart would be the ticket but it only accepts numerical values. I need to have discrete string categories on my Y-axis.

If anyone can point me in the right direction, you would really make my day. Thanks for reading!

-Christine

(The code below works as-is. It is as simple as I could make it)

import java.awt.Dimension;

import javax.swing.JPanel;

import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.time.Day;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

public class EventFrequencyDemo1 extends ApplicationFrame   
{   
    public EventFrequencyDemo1(String s)   
    {   
        super(s);   
        CategoryDataset categorydataset = createDataset();   
        JFreeChart jfreechart = createChart(categorydataset);   
        ChartPanel chartpanel = new ChartPanel(jfreechart);   
        chartpanel.setPreferredSize(new Dimension(500, 270));   
        setContentPane(chartpanel);   
    }   

    private static JFreeChart createChart(CategoryDataset categorydataset)   
    {   
        CategoryPlot categoryplot = new CategoryPlot(categorydataset, new CategoryAxis("Category"), new DateAxis("Date"), new LineAndShapeRenderer(false, true));
        categoryplot.setOrientation(PlotOrientation.HORIZONTAL);
        categoryplot.setDomainGridlinesVisible(true);
        return new JFreeChart(categoryplot);   
    }   

    private static CategoryDataset createDataset()   
    {   
        DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();   
        Day june10 = new Day(10, 6, 2002);   
        Day june20 = new Day(20, 6, 2002);
        // This event is overwritten by June20th
        defaultcategorydataset.setValue(new Long(june10.getMiddleMillisecond()), "Event Type 1", "Category 1");   
        defaultcategorydataset.setValue(new Long(june10.getMiddleMillisecond()), "Event Type 1", "Category 2");   
        // Overwrites the previous June10th event
        defaultcategorydataset.setValue(new Long(june20.getMiddleMillisecond()), "Event Type 1", "Category 1");   
        defaultcategorydataset.setValue(new Long(june20.getMiddleMillisecond()), "Event Type 2", "Category 2");   
        return defaultcategorydataset;   
    }   

    public static JPanel createDemoPanel()   
    {   
        JFreeChart jfreechart = createChart(createDataset());   
        return new ChartPanel(jfreechart);   
    }   

    public static void main(String args[])   
    {   
        EventFrequencyDemo1 eventfrequencydemo1 = new EventFrequencyDemo1("Event Frequency Demo");   
        eventfrequencydemo1.pack();   
        RefineryUtilities.centerFrameOnScreen(eventfrequencydemo1);   
        eventfrequencydemo1.setVisible(true);   
    }   
}  
  • 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-05-14T08:32:15+00:00Added an answer on May 14, 2026 at 8:32 am

    In addition to @Jeff Storey’s suggestions, you may get some inspiration from the JFreeChart Samples, and don’t overlook the Demo application, available via Java Web Start. I’m not sure I follow your requirements, but DefaultMultiValueCategoryDataset is described as “A category dataset that defines multiple values for each item.”

    Addendum: If you want to stick with LineAndShapeRenderer, both LineAndShapeRenderer(false, true) and setBaseLinesVisible() can preclude line drawing.

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

Sidebar

Related Questions

I still very new using Subversion. Is it possible to have a working copy
I am fairly new at using the ASP.NET MVC framework and was hoping that
I have a question about using new[] . Imagine this: Object.SomeProperty = new[] {string1,
I'm new to using the NetBeans IDE. When I try to look at the
I'm new to using LINQ to Entities (or Entity Framework whatever they're calling it)
I am fairly new to using infragistics controls (started yesterday). While they are (very)
I am relatively new to using jQuery and would like to use the load
I'm new to using open source libraries in production code so when it says
I'm kinda new to using Rails, and an app I am working on is
How exactly can I create a new directory using Emacs? What commands do I

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.