- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个图表,其中 x 轴显示时间,y 轴显示我的数据。我想通过为 x 轴选择不同的指标来更改比例。例如秒、分钟和小时刻度。默认是第二个。因此,如果我选择分钟,图表应该更小并且更弯曲。任何想法? UI 尚未完成,但您认为会有 x 轴和 y 轴。参数 Degree 决定了它应该缩放到秒( Degree=1 ),分钟(度=60)或小时(度=3600)
private void drawLines(Graphics g, ArrayList<Point> 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());
}
}
最佳答案
考虑使用jfreechart ,缩放图形以填充封闭容器。在示例中看到 here ,封闭容器是一个 ChartPanel
,它添加到框架默认 BorderLayout
的 CENTER
中。这将允许图形随着封闭框架大小的调整而增大和缩小。
一般方案使用linear interpolation映射模型和 View 坐标。 。给定以下比例,您可以叉乘并求解缺失的坐标,如完整的example所示将鼠标坐标映射到图像中的像素坐标。
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?
是的,如@MadProgrammer comments ,你可以
使用上面显示的比例将数据缩放到封闭容器。 example引用孤立的基本方法; JFreeChart
是一个功能齐全的示例。
使用 BufferedImage
将渲染的图像缩放到封闭容器。这个example's ComponentHandler
绘制到 BufferedImage
中,该图像的大小可填充封闭的 JPanel
。 背景
图像在paintComponent()
的实现中渲染。调整框架大小以查看效果。
关于java - 如何在Java中更改图表比例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35234941/
我是一名优秀的程序员,十分优秀!