swing - How to change diagram Scale in Java -
i have diagram in x axis shows time , y axis shows data. want change scale choosing different metrics x axis. e.g second, minute , hour scale. default second. therefore if choose minute diagram should smaller , more curved. idea? ui not completed suppose there x , y axis. parameter degree determines should scaled second(degree=1), minute (degree=60) or hour(degree=3600)
private void drawlines(graphics g, arraylist<point> points,int degree) throws exception { if (points == null || points.isempty()) { throw new exception("no points found!!!"); } (int = 0; < points.size() - 1; i++) { point firstpoint = points.get(i); point secondpoint = points.get(i + 1); g.drawline((int) firstpoint.getx(), (int) firstpoint.gety(), (int) secondpoint.getx(), (int) secondpoint.gety()); } }
consider using jfreechart, scales graph fill enclosing container. in example seen here, enclosing container chartpanel added center of frame's default borderlayout. allow graph grow , shrink enclosing frame resized.

the general scheme maps model , view coordinates using linear interpolation. given following proportions, can cross-multiply , solve missing coordinate, shown in complete example maps mouse coordinates pixel coordinates in image.
view.x : panelwidthinpixels :: model.x : modelxrange view.y : panelheightinpixels :: model.y : modelyrange i not want use
jfreechart. there other way?
yes, @madprogrammer comments, can
scale data enclosing container using proportions shown above. example cited isolates basic approach;
jfreechartfull featured example.scale rendered image enclosing container using
bufferedimage. example'scomponenthandlerdrawsbufferedimagesized fill enclosingjpanel.backgroundimage rendered in implementation ofpaintcomponent(). resize frame see effect.scale rendered image enclosing container using transform applied graphics context. typical examples shown here , here.

Comments
Post a Comment