java - JFreechart & Servlet: How to compute datapoint from mouse position -
i'm drawing within servlet scatterplot , serve browser. user can click somewhere on plot , want determine datapoint of scatter plot user has pointed. mouse click of user can determine on pixel of image has clicked, how can info coordinates on domain , range axis?
i found tipps how it, uses chartpanel. serving directly browser use instance of jfreechar object.
anybody has clue or example how it?
thanks, dieter
i think have found solution. solution need chart again, either have create new or save somehow. when have reference chart solution following:
jfreechart chart = functionwhichretrievesthechart(); chartrenderinginfo info = new chartrenderinginfo(); // plot_size size if graph , has same size original drawn chart.createbufferedimage(plot_size, plot_size, info); graph, otherwise pixel position points somewhere else plotrenderinginfo plotinfo = info.getplotinfo(); xyplot plot = (xyplot)chart.getplot(); point p = new point(x,y); // x , y pixel positions // domain value belongs pixel position x double domain = plot.getdomainaxis().java2dtovalue(p.getx(), plotinfo.getdataarea(), plot.getdomainaxisedge()); // range value belongs pixel position y double range = plot.getrangeaxis().java2dtovalue(p.gety(), plotinfo.getdataarea(), plot.getrangeaxisedge());
Comments
Post a Comment