Coder Social home page Coder Social logo

Comments (8)

trashgod avatar trashgod commented on August 23, 2024

Add a ChartMouseListener, seen here, to your view component.

from jfreechart.

shsen avatar shsen commented on August 23, 2024

Thank you for your reply, but the link is show "Human verification"...
Can you copy the sample code to here?
Thanks.

from jfreechart.

trashgod avatar trashgod commented on August 23, 2024

I see it, too. After verifying, refine your search according to your use case. Failing that, more examples are archived here.

from jfreechart.

shsen avatar shsen commented on August 23, 2024

I see many examples use XYPlot, and I use CategoryPlot, so it no use for me...

my code as below:

DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(500, "Line1", "2023.05.01");
dataset.addValue(300, "Line2", "2023.05.01");
dataset.addValue(700, "Line1", "2023.05.02");
dataset.addValue(500, "Line2", "2023.05.02");
...
chart = ChartFactory.createLineChart("","","",dataset, PlotOrientation.VERTICAL,true,true,false);
...

//show chart Frame:
public class OverlayFrame extends JFrame
{
static JFrame frame = null;
static String strTitle = "";
static class MyPanel extends JPanel implements ChartMouseListener
{
private ChartPanel chartPanel;
public MyPanel(JFreeChart chart)
{
super(new BorderLayout());
this.chartPanel = new ChartPanel(chart);
this.chartPanel.addChartMouseListener(this);
add(this.chartPanel);
}

    public void chartMouseClicked(ChartMouseEvent event)
    {
        /*JFreeChart chart = event.getChart();
        CategoryPlot plot = chart.getCategoryPlot();
        CategoryAxis xAxis = plot.getDomainAxis();
        //plot.setDomainAxis(xAxis);
        Comparable c = plot.getDomainCrosshairColumnKey();
        if (c != null)
        {
            frame.setTitle(c.toString());
        }
        plot.setDomainCrosshairVisible(true);
        plot.setRangeCrosshairVisible(true);*/
        //frame.setTitle(xAxis.getCategoryLabelToolTip(plot.getDomainCrosshairColumnKey()));
        //frame.setTitle(strTitle + "Hello");
    }

    public void chartMouseMoved(ChartMouseEvent event)
    {
        JFreeChart chart = event.getChart();
        CategoryPlot plot = chart.getCategoryPlot();
        Comparable cx = plot.getDomainCrosshairColumnKey();
        Comparable cy = plot.getDomainCrosshairRowKey();
        if (cx != null)
        {
            frame.setTitle(cx + "   " + cy);
        }
        plot.setDomainCrosshairVisible(true);
    }
}

public OverlayFrame(String title, JFreeChart chart)
{
    super(title);
    setContentPane(new MyPanel(chart));
    frame = this;
    strTitle = title;
}

}

so, how to get the value(2 Line have 2 value) and date(only one) to show in frame title???

from jfreechart.

trashgod avatar trashgod commented on August 23, 2024

Focusing on the mouse event's ChartEntity, the listener below displays each of the four points as the mouse is moved over them.

@Override
public void chartMouseClicked(ChartMouseEvent cme) {
	report(cme.getEntity());
}

@Override
public void chartMouseMoved(ChartMouseEvent cme) {
	report(cme.getEntity());
}

private void report(ChartEntity ce) {
	if (ce instanceof CategoryItemEntity cie) {
		chart.setTitle(cie.getRowKey() + " " + cie.getColumnKey());
	}
}

from jfreechart.

shsen avatar shsen commented on August 23, 2024

if (event.getEntity() instanceof CategoryItemEntity)
{
frame.setTitle(((CategoryItemEntity) event.getEntity()).getRowKey() + " " + ((CategoryItemEntity) event.getEntity()).getColumnKey());
}

it can work, thank you. but it is not my request, I want to show the all lines value when the mouse move aross the date column, not the mouse point move in the entity. And show the DomainCrosshair (just use plot.setDomainCrosshairVisible(true))...

from jfreechart.

trashgod avatar trashgod commented on August 23, 2024

Since your domain axis is a CategoryAxis, it looks like you may be able to use getCategoryStart|Middle|End methods to get the domain bound for each row key; you can then determine which column includes cme.getTrigger().getX().

from jfreechart.

shsen avatar shsen commented on August 23, 2024

Thank you!I use JSlider and barely solve the demand.

from jfreechart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.