swing - How to change diagram Scale in Java -


enter image description here

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 , 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.

image

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; jfreechart full featured example.

  • scale rendered image enclosing container using bufferedimage. example's componenthandler draws bufferedimage sized fill enclosing jpanel. background image rendered in implementation of paintcomponent(). resize frame see effect.

  • scale rendered image enclosing container using transform applied graphics context. typical examples shown here , here.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -