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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:55:00+00:00 2026-06-17T14:55:00+00:00

I would like put text over each point I plotted in a line chart.

  • 0

I would like put text over each point I plotted in a line chart.

This is what I can do:what I can do

And this is what I need (names of point are in green):what I need

  • 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-17T14:55:01+00:00Added an answer on June 17, 2026 at 2:55 pm

    The StandardXYItemLabelGenerator should work; there’s an example here.

    Addendum: The labels you can see in the picture are in a separate string array.

    Such labels may be incorporated in the XYDataset, as shown in LabeledXYDataset below. Because none of the features of StandardXYItemLabelGenerator are used, a custom implementation of XYItemLabelGenerator is sufficient. The XYItemRenderer controls the color, size and relative position of the labels.

    Addendum: How can I add tooltips?

    Guided by ChartFactory.createXYLineChart(), simply specify a XYToolTipGenerator to the renderer. The default format, seen here, is Series: (x, y).

    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    

    image

    import java.awt.Color;
    import java.awt.Dimension;
    import java.util.ArrayList;
    import java.util.List;
    import javax.swing.JFrame;
    import org.jfree.chart.*;
    import org.jfree.chart.axis.NumberAxis;
    import org.jfree.chart.labels.ItemLabelAnchor;
    import org.jfree.chart.labels.ItemLabelPosition;
    import org.jfree.chart.labels.XYItemLabelGenerator;
    import org.jfree.chart.labels.StandardXYToolTipGenerator;
    import org.jfree.chart.plot.XYPlot;
    import org.jfree.chart.renderer.xy.XYItemRenderer;
    import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
    import org.jfree.data.xy.AbstractXYDataset;
    import org.jfree.data.xy.XYDataset;
    import org.jfree.ui.TextAnchor;
    
    /** @see https://stackoverflow.com/a/14459322/230513 */
    public class UnitPrice {
    
        private static XYDataset createDataset() {
            LabeledXYDataset ds = new LabeledXYDataset();
            ds.add(11,  0, "");
            ds.add(12, 68, "A");
            ds.add(13, 65, "B");
            ds.add(14, 67, "C");
            ds.add(15, 69, "D");
            ds.add(16, 60, "F");
            ds.add(17, 83, "G");
            ds.add(18, 86, "H");
            ds.add(19, 70, "I");
            ds.add(20, 60, "J");
            ds.add(21, 55, "K");
            ds.add(22, 54, "L");
            ds.add(23, 50, "M");
            return ds;
        }
    
        private static class LabeledXYDataset extends AbstractXYDataset {
    
            private static final int N = 26;
            private List<Number> x = new ArrayList<Number>(N);
            private List<Number> y = new ArrayList<Number>(N);
            private List<String> label = new ArrayList<String>(N);
    
            public void add(double x, double y, String label){
                this.x.add(x);
                this.y.add(y);
                this.label.add(label);
            }
    
            public String getLabel(int series, int item) {
                return label.get(item);
            }
    
            @Override
            public int getSeriesCount() {
                return 1;
            }
    
            @Override
            public Comparable getSeriesKey(int series) {
                return "Unit";
            }
    
            @Override
            public int getItemCount(int series) {
                return label.size();
            }
    
            @Override
            public Number getX(int series, int item) {
                return x.get(item);
            }
    
            @Override
            public Number getY(int series, int item) {
                return y.get(item);
            }
        }
    
        private static class LabelGenerator implements XYItemLabelGenerator {
    
            @Override
            public String generateLabel(XYDataset dataset, int series, int item) {
                LabeledXYDataset labelSource = (LabeledXYDataset) dataset;
                return labelSource.getLabel(series, item);
            }
    
        }
    
        private static JFreeChart createChart(final XYDataset dataset) {
            NumberAxis domain = new NumberAxis("Unit");
            NumberAxis range = new NumberAxis("Price");
            domain.setAutoRangeIncludesZero(false);
            XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
            renderer.setBaseItemLabelGenerator(new LabelGenerator());
            renderer.setBaseItemLabelPaint(Color.green.darker());
            renderer.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
            renderer.setBaseItemLabelFont(
                renderer.getBaseItemLabelFont().deriveFont(14f));
            renderer.setBaseItemLabelsVisible(true);
            renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            XYPlot plot = new XYPlot(dataset, domain, range, renderer);
            JFreeChart chart = new JFreeChart(
                "Unit Price", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
            return chart;
        }
    
        public static void main(String[] args) {
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            XYDataset dataset = createDataset();
            JFreeChart chart = createChart(dataset);
            ChartPanel chartPanel = new ChartPanel(chart) {
    
                @Override
                public Dimension getPreferredSize() {
                    return new Dimension(400, 320);
                }
            };
            f.add(chartPanel);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This XAML makes text fade in when it appears. I would like to put
I have text file with some stuff that i would like to put into
I would like to put a time & date stamp on each row added
I would like to put text inside a bubble, and I want that my
In the below code I would like to put a variable to the text
I'm trying to put in RelativeLayout an image and text, and would like the
For various reasons, I need to put a (mostly) transparent <div> over some text.
I would like to put newlines in a property value of a manifest. Its
I would like to put a button on top of a Google Map next
I would like to put a placeholder into e.g. the footer.html and have it

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.