Comments (8)
Add a ChartMouseListener
, seen here, to your view component.
from jfreechart.
Thank you for your reply, but the link is show "Human verification"...
Can you copy the sample code to here?
Thanks.
from jfreechart.
I see it, too. After verifying, refine your search according to your use case. Failing that, more examples are archived here.
from jfreechart.
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.
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.
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.
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.
Thank you!I use JSlider and barely solve the demand.
from jfreechart.
Related Issues (20)
- set axis arrow and location HOT 1
- P&F chart HOT 1
- About Jakarta EE 9 HOT 6
- Removing space before and after chart HOT 8
- Publish latest javadoc HOT 1
- Histogram : How to only have integer tick in the x axis HOT 1
- org.jfree.chart.labels.ItemLabelPosition class not cloneable HOT 1
- Rotate X-axis labels vertically HOT 10
- bogus CVE claimed on this project HOT 12
- Unnecessary reference to Swing in headless mode causes considerable delay HOT 3
- Multiple vulnerabilities in jfreechart to be solved in both 1.5.x (with JDK 1.8) and 2.x (with JDK >= 1.11)? HOT 2
- Quarter constructor does not validate quarter and year parameter ranges.
- Inquiry About JFreeChart License Discrepancy Between Maven and Git Repositories HOT 4
- Vulnerable Code HOT 3
- 不给问题 HOT 2
- Main web page is still on JFreeChart 1.5.3
- Anomaly while building JFreeChart v1.5.5 HOT 2
- CVE vulnerabilities on Jfreechart
- NaN Values in PolarPlots HOT 7
- SpiderWebPlot HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jfreechart.