简体   繁体   English

绘制Java 2D图表跨越多个视图或面板或水平滚动

[英]Drawing Java 2D Charts span across multiple views or panels or horizontal-scrolling

I'm drawing a graph using Java 2d graphics (ie drawing and filling rectangles) straightaway on a JFrame from a set of values stored in an Arraylist. 我正在使用Java 2d图形(即绘制和填充矩形)在JFrame上从存储在Arraylist中的一组值中直接绘制图形。 But when the ArrayList has very large number of values (can even go upto 3500 in size), the drawing is compressed - where the graph seems less informative and even the labels on the X-axis are not displayed. 但是,当ArrayList具有非常多的值(甚至可以扩展到3500)时,图形将被压缩-图形看上去信息量不足,甚至X轴上的标签也不会显示。 Is there a way I can make the graph displayable in several page-wise manner (ie say limiting so that a page can show upto 100 values - the remaining in different pages where the user can navigate page-wise). 有没有一种方法可以使图形以几种页面方式显示(即限制显示,以便一个页面最多可以显示100个值-其余部分可以在用户可以按页面导航的不同页面中显示)。

How can I approach this type of a situation? 我该如何处理这种情况? Are there any stacked-layouts I can use? 我可以使用任何堆叠式布局吗? Can I use panels? 我可以使用面板吗? But then can I draw half way in panels (since the graph is drawn inside a loop - until the elements of arraylist are read)? 但是,然后我可以在面板上绘制一半吗(因为图形是在循环内绘制的-直到读取arraylist的元素为止)? Or can I have a scrollable panel? 还是可以有一个可滚动的面板? I have currently drawn everything manually without using drag-and-drop GUI in NetBeans. 我目前已经手动绘制了所有内容,而没有在NetBeans中使用拖放GUI。

Greatly appreciate any insight, suggestions and ideas. 非常感谢任何见解,建议和想法。

Many thanks in advance 提前谢谢了

A quick solution is to just put your panel in a JScrollPane . 一种快速的解决方案是将面板放入JScrollPane中 You could also use a card layout . 您也可以使用卡片布局 Just put the graph on n pages and show 1/nth part of the graph on each page. 只需将图形放在n页上,然后在每页上显示图形的1 / n部分。 That should be relatively easily since you are drawing the graph yourself. 这应该相对容易,因为您自己绘制图形。 Frankly though, you don't even need a card layout for what you are doing. 坦白说,您所做的工作甚至不需要卡片布局。 When the button is pushed just tell your chartpanel what portion of the graph to show and have it update itself accordingly. 按下按钮时,只需告诉您的图表面板要显示的图形的哪一部分,并对其进行相应的更新即可。

Another option is to use a charting library instead of creating your chart manually. 另一种选择是使用图表库,而不是手动创建图表。 JFreeChart is a commonly used library which allows the user to zoom in and out of the chart. JFreeChart是一个常用的库,它允许用户放大和缩小图表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM