java中scale什么意思,如何在Java中更改图表Scale

XqL5t.jpg

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, minute and hour scale. the default is second. therefore if I choose the minute the diagram should be smaller and be more curved. Any idea? The UI is not completed however you suppose that the there would be x and y axis. The parameter degree determines that It should be scaled to second(degree=1),

minute (degree=60) or hour(degree=3600)

private void drawLines(Graphics g, ArrayList points,int degree) throws Exception {

if (points == null || points.isEmpty()) {

throw new Exception("No points found!!!");

}

for (int i = 0; i < 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, 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.

dKHVg.png

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值