Hi
How can we remove a subplot from combineddomainxyplot...?
I am making some stock charts and adding indicators on them on demand, and want to remove when its not needed.
Thanks
How to remove subplot from combineddomainxyplot
-
- Posts: 58
- Joined: Mon Dec 15, 2008 7:07 am
- Location: India
- Contact:
How to remove subplot from combineddomainxyplot
Abhay Singh
Re: How to remove subplot from combineddomainxyplot
Code: Select all
public void remove(XYPlot subplot)
-
- Posts: 58
- Joined: Mon Dec 15, 2008 7:07 am
- Location: India
- Contact:
Re: How to remove subplot from combineddomainxyplot
Thanks,
But how do i know which plot its removing? i wanted to remove any specific one.
In my case am adding charts to combineddomain on selection, if i unselected that selection then i want to
remove that.
e.g
I have created price-volume chart, now i want to add moving Avg chart to this, again like this i will
add couple of more charts. and in same way i want to remove them(definatly not in same order, its a random).
Hope i am able to explain my problem.
But how do i know which plot its removing? i wanted to remove any specific one.
In my case am adding charts to combineddomain on selection, if i unselected that selection then i want to
remove that.
e.g
I have created price-volume chart, now i want to add moving Avg chart to this, again like this i will
add couple of more charts. and in same way i want to remove them(definatly not in same order, its a random).
Hope i am able to explain my problem.
Abhay Singh
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: How to remove subplot from combineddomainxyplot
I am not sure to how achieve what you have described as "selection of a chart" (btw, we are still talking about plots, not charts, right?)
In general, if you want to add items to a chart or plot, and need to remove a specific item later in a controlled way (i.e. only one specific item), you will probably have to store references to these items in your own logic.
For instance, you could create a JPanel with JCheckBoxes, and everytime you add a sub plot to the combined plot, create a JCheckBox for that plot (to assign a JCheckBox to plot should be easily possible with a HashMap). If the JCheckBox is deselected, remove it from the panel and remove the corresponding plot from the combined plot. A similar approach should also work for Titles, Markers, Annotations...
You could also attach a ChartMouseListener to the ChartPanel and listen for ChartMouseEvents. Then, extract the original MouseEvent from the ChartMouseEvent, get the coordinates of the event, query the ChartRenderingInfo from the ChartPanel and extract the PlotRenderingInfo, and call findSubplot(PlotRenderingInfo info,Point2D source) on your combined plot.
In general, if you want to add items to a chart or plot, and need to remove a specific item later in a controlled way (i.e. only one specific item), you will probably have to store references to these items in your own logic.
For instance, you could create a JPanel with JCheckBoxes, and everytime you add a sub plot to the combined plot, create a JCheckBox for that plot (to assign a JCheckBox to plot should be easily possible with a HashMap). If the JCheckBox is deselected, remove it from the panel and remove the corresponding plot from the combined plot. A similar approach should also work for Titles, Markers, Annotations...
You could also attach a ChartMouseListener to the ChartPanel and listen for ChartMouseEvents. Then, extract the original MouseEvent from the ChartMouseEvent, get the coordinates of the event, query the ChartRenderingInfo from the ChartPanel and extract the PlotRenderingInfo, and call findSubplot(PlotRenderingInfo info,Point2D source) on your combined plot.
-
- Posts: 58
- Joined: Mon Dec 15, 2008 7:07 am
- Location: India
- Contact:
Re: How to remove subplot from combineddomainxyplot
I am a little confused about what you are trying to do, simply because a moving average plot is normally displayed superimposed over the price plot. In that case, you would have used setDataset(...)/mapDatasetToRangeAxis(...) to add each subsequent dataset to the plot. There is no way to remove a dataset from the plot. If you wish to "hide it", you should obtain a reference to the renderer and then call
Code: Select all
public void setSeriesVisible(int series, Boolean visible, boolean notify)
-
- Posts: 58
- Joined: Mon Dec 15, 2008 7:07 am
- Location: India
- Contact:
Re: How to remove subplot from combineddomainxyplot
Hi,
first of all thanks for replying and showing intereset on my topic
What i am trying to do is...
I am making an application where we can analysze market performance of any listed company, these analysis done on basis of some technical indicators like Moving Avg, MACD, williums %R, Rate of Change etc....
If you select a company and the period for which you want to analyze, By default i show its price-volume chart, afterwards you can add as many as indicators (The indicators are nothing but some plot, either line or bar plot based on some mathmetical calculation on data)you want and also you can remove them, you draw trend line etc ...
So my problem was removing added indicator-plot from my whole chart.
Yes i know Moving average is super imposed on same plot(in price plot)( i just taken that as e.g)...
yes i have used setDataset and setRenderer methods to plot Moving Avg on price plot.
I am not using what you have suggested to hide this data series from the plot. i am doing some thing like this
please let me know if its correct
In my case there can be either 2 or 4 dataset in xyplot.
Dataset = 4 when current price, prev close, MA of current price and MA of prev close.
Dataset = 2 when current price and MA of current price.
I have plans to do lot more but i am not that efficient in java and jfree, see where i reach
.
do you any idea how i can draw line in my chart via mouse clicks, means first click will set one coordinate then i will drag mouse till i
want to draw it.. .?
first of all thanks for replying and showing intereset on my topic
What i am trying to do is...
I am making an application where we can analysze market performance of any listed company, these analysis done on basis of some technical indicators like Moving Avg, MACD, williums %R, Rate of Change etc....
If you select a company and the period for which you want to analyze, By default i show its price-volume chart, afterwards you can add as many as indicators (The indicators are nothing but some plot, either line or bar plot based on some mathmetical calculation on data)you want and also you can remove them, you draw trend line etc ...
So my problem was removing added indicator-plot from my whole chart.
Yes i know Moving average is super imposed on same plot(in price plot)( i just taken that as e.g)...
yes i have used setDataset and setRenderer methods to plot Moving Avg on price plot.
I am not using what you have suggested to hide this data series from the plot. i am doing some thing like this
please let me know if its correct
Code: Select all
int ix = xyplot.getDatasetCount();
xyplot.setDataset((ix-1), null);
if(ix == 4)
xyplot.setDataset((ix-2), null);
Dataset = 4 when current price, prev close, MA of current price and MA of prev close.
Dataset = 2 when current price and MA of current price.
I have plans to do lot more but i am not that efficient in java and jfree, see where i reach

do you any idea how i can draw line in my chart via mouse clicks, means first click will set one coordinate then i will drag mouse till i
want to draw it.. .?
Abhay Singh