How to change diagram Scale in Java

前端 未结 1 557
执笔经年
执笔经年 2021-01-16 15:17

I have a diagram in which x axis shows the time and the y axis shows my data. I want to change the Scale by choosing different metrics for x axis. e.g second, minu

相关标签:
1条回答
  • 2021-01-16 15:49

    Consider using jfreechart, which scales the graph to fill the enclosing container. In the example seen here, the enclosing container is a ChartPanel that is added to the CENTER of frame's default BorderLayout. This will allow the graph to grow and shrink as the enclosing frame is resized.

    image

    The general scheme maps model and view coordinates using linear interpolation. Given the following proportions, you can cross-multiply and solve for the missing coordinate, as shown in this complete example that maps mouse coordinates to pixel coordinates in an image.

    view.x : panelWidthInPixels :: model.x : modelXRange
    view.y : panelHeightInPixels :: model.y : modelYRange
    

    I do not want to use the JFreeChart. Is there any other way?

    Yes, as @MadProgrammer comments, you can

    • Scale the data to the enclosing container using the proportions shown above. The example cited isolates the basic approach; JFreeChart is a full featured example.

    • Scale the rendered image to the enclosing container using a BufferedImage. This example's ComponentHandler draws into a BufferedImage that is sized to fill the enclosing JPanel. The background image is rendered in the implementation of paintComponent(). Resize the frame to see the effect.

    • Scale the rendered image to the enclosing container using a transform applied to the graphics context. Typical examples are shown here and here.

    0 讨论(0)
提交回复
热议问题