Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add XYBezierRenderer to jfreechart #286

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

JRobes
Copy link

@JRobes JRobes commented Mar 10, 2022

Plot charts using Bezier curves.
With Bezier curves you can control how the curve fits (bends) to the points on the graph. This is done with the parameter 'tension'
This solution arises from the problem defined in stackoverflow:
StackOverflow question

XYBezierRenderer extends XYLineAndShapeRenderer.
XYBezierRendererTest has been also added to branch.

plot charts using Bezier curves (the tension parameter controls how the
curve bends arround the points
@jfree
Copy link
Owner

jfree commented Jun 16, 2022

This looks really interesting, I will take a closer look

@JRobes
Copy link
Author

JRobes commented Jun 16, 2022

I'm glad to hear that. Do not hesitate to ask me if you need further details.
The pictures created are really fine as you could check in mudiaurum.com => graphics (7 days pictures)

@jfree
Copy link
Owner

jfree commented Jun 17, 2022

The link didn't work for me. Anyway I created a small demo program to try out the renderer (see below). It seems to work well for the line rendering but I noticed the FillType options aren't fully working yet.

image

/* --------------------------
 * XYBezierRendererDemo1.java
 * --------------------------
 * (C) Copyright 2022, by David Gilbert.
 *
 */

package org.jfree.chart.demo;

import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardXYToolTipGenerator;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYBezierRenderer;
import org.jfree.chart.swing.ApplicationFrame;
import org.jfree.chart.swing.ChartPanel;
import org.jfree.chart.swing.UIUtils;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

/**
 * A simple demonstration of the {@link XYBezierRenderer} class.
 */
public class XYBezierRendererDemo1 extends ApplicationFrame {

    /**
     * Constructs the demo application.
     *
     * @param title  the frame title.
     */
    public XYBezierRendererDemo1(String title) {
        super(title);
        JPanel chartPanel = createDemoPanel();
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));
        setContentPane(chartPanel);
    }

    /**
     * Creates a sample chart.
     *
     * @param dataset  a dataset for the chart.
     *
     * @return A sample chart.
     */
    private static JFreeChart createChart(XYDataset dataset) {
        JFreeChart chart = ChartFactory.createXYLineChart("XYBezierRenderer Demo 1", "X", "Y", dataset);
        XYPlot plot = (XYPlot) chart.getPlot();
        plot.setDomainPannable(true);
        plot.setRangePannable(true);
        XYBezierRenderer renderer = new XYBezierRenderer(10, 25, XYBezierRenderer.FillType.TO_ZERO);
        renderer.setSeriesLinesVisible(0, true);
        renderer.setSeriesShapesVisible(0, false);
        renderer.setSeriesLinesVisible(1, true);
        renderer.setSeriesShapesVisible(1, true);
        renderer.setDefaultToolTipGenerator(new StandardXYToolTipGenerator());
        renderer.setDefaultEntityRadius(6);
        plot.setRenderer(renderer);
        return chart;
    }

    /**
     * Creates a sample dataset.
     *
     * @return A dataset.
     */
    private static XYDataset createDataset() {
        XYSeries series1 = new XYSeries("Series 1");
        series1.add(1.0, 3.3);
        series1.add(2.0, 4.4);
        series1.add(3.0, 1.7);
        XYSeries series2 = new XYSeries("Series 2");
        series2.add(1.0, 7.3);
        series2.add(2.0, 0.0);
        series2.add(3.0, 9.6);
        series2.add(4.0, 5.6);
        XYSeriesCollection dataset = new XYSeriesCollection();
        dataset.addSeries(series1);
        dataset.addSeries(series2);
        return dataset;
    }

    /**
     * Creates a panel for the demo (used by SuperDemo.java).
     *
     * @return A panel.
     */
    public static JPanel createDemoPanel() {
        JFreeChart chart = createChart(createDataset());
        ChartPanel panel = new ChartPanel(chart);
        panel.setMouseWheelEnabled(true);
        return panel;
    }

    /**
     * Starting point for the demonstration application.
     *
     * @param args  ignored.
     */
    public static void main(String[] args) {
        XYBezierRendererDemo1 demo = new XYBezierRendererDemo1(
                "JFreeChart: XYBezierRendererDemo1.java");
        demo.pack();
        UIUtils.centerFrameOnScreen(demo);
        demo.setVisible(true);
    }

}

@trashgod
Copy link
Contributor

For reference, I get the same result:

$ host mudiaurum.com
Host mudiaurum.com not found: 3(NXDOMAIN)
$ git clone https://github.com/JRobes/jfreechart.git robes
$ pushd robes
$ git checkout jrobes/2.0.0
$ mvn clean compile
$ javac -cp target/classes XYBezierRendererDemo1.java
$ java -cp .:target/classes:$JFC XYBezierRendererDemo1

@JRobes
Copy link
Author

JRobes commented Jun 17, 2022

Typing
mundiaurum.com
in any browser should work

@jfree
Copy link
Owner

jfree commented Jun 18, 2022

Ah, that link works. Looks very nice.

javier added 2 commits April 21, 2023 12:17
@JRobes
Copy link
Author

JRobes commented Apr 21, 2023

I have modified XYBezierRenderer to fix the bug commented by David about the FillType options.
Now the FillType options works fine, see plot below:

bezier

@coreagile
Copy link

This is fantastic! When can it get merged?

@JRobes
Copy link
Author

JRobes commented Dec 19, 2023

I have uploaded the code but I don know how to merge the pull request.
Any help is welcomed

@trashgod
Copy link
Contributor

@coreagile : Pending a merge by the owner, anyone can clone JRobes' JFreeChart fork, found here, and test it as shown here.

@JRobes : I haven't had a chance to look at your later commits. If I understand correctly, you would only need to consider merging pull requests submitted by others to your fork. This workflow guide may be relevant.

Copy link
Author

@JRobes JRobes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to merge this pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants