Hi,
I am question about how to implement a function for selecting one line(series) in line chart.
specifically, if I have a line chart, there are several lines in the chart, how can I implement selection of one line(series)
by double(single) click mouse. And then the selected line is highlighted all.
Appreciate for any comments!!
Tain
how to implement selecting one line(series) in line chart
-
- Posts: 47
- Joined: Thu Dec 11, 2008 7:59 pm
Re: how to implement selecting one line(series) in line chart
There is no highlighting functionality built in that I know of, but you can simulate a highlight by changing the line color and line thickness on a mouse click. The only downside is that the user must click on a datapoint, a click on the line between datapoints wont register.
Code: Select all
chartPanel.addChartMouseListener(new ChartMouseListener()
{
public void chartMouseClicked(ChartMouseEvent event)
{
ChartEntity entity = event.getEntity();
if (entity instanceof PlotEntity)
{
// User clicked an empty space on the plot so clear all highlights.
// This requires some logic to restore the original series colors and thickness,
// such as using a Vector to store the original values and reapplying them here.
// Here I am just reverting the first series back to red and normal thickness.
chartPanel.getChart().getXYPlot().getRenderer().setSeriesPaint(0, Color.RED);
chartPanel.getChart().getXYPlot().getRenderer().setSeriesStroke(0, new BasicStroke(1.0f));
}
if (entity instanceof XYItemEntity)
{
// User clicked on an XYDataset
XYItemEntity xyEntity = (XYItemEntity) entity;
int seriesIndex = xyEntity.getSeriesIndex();
// Here I am setting the clicked series to red and increasing the line thickness.
chartPanel.getChart().getXYPlot().getRenderer().setSeriesPaint(seriesIndex, Color.BLUE);
chartPanel.getChart().getXYPlot().getRenderer().setSeriesStroke(seriesIndex, new BasicStroke(2.0f));
}
}
public void chartMouseMoved(ChartMouseEvent event) {}
});
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: how to implement selecting one line(series) in line chart
A "selection mechanism" for individual data points has been requested before: see here.
Maybe you can get some additional hints on how to implement a "selection aware" renderer.
Maybe you can get some additional hints on how to implement a "selection aware" renderer.
Re: how to implement selecting one line(series) in line chart
Appreciate it!!!
Tain
Tain