JfreeChart 中的自动缩放 Y 轴
我正在使用 JFreeChart
在我的 Java 应用程序中创建蜡烛图。但是,我的图表最终看起来像这样:
http://imageshack.us/photo/my-images/69/capturebhx。 png/
我希望 Y 轴自动缩放,以便图表看起来更像这样:
http://imageshack.us/photo/my-images/717/capture2wl。 png/
我认为 org.jfree.chart.axis.NumberAxis.configure() 会执行此操作,但我不确定。我似乎找不到将我的 JFreeChart 对象或 ChartPanel 对象与此 NumberAxis 对象绑定的方法。请帮助我,我迷路了,一直在寻找很长时间来尝试将这些物体绑在一起。或者,如果您能找到其他方法,那就太好了!
一些代码:
...
private DefaultHighLowDataset dataset;
private JFreeChart chart;
private ChartPanel chart_panel;
...
// creates dataset, then chart from dataset, then chart_panel from chart
dataset = new DefaultHighLowDataset("", date, high, low, open, close, volume);
chart = ChartFactory.createCandlestickChart("Blank", "Time", "Price", dataset, false);
chart_panel = new ChartPanel(chart); // what you see in the images
...
I am using JFreeChart
to create candlestick charts in my Java app. However, my charts end up looking like this:
http://imageshack.us/photo/my-images/69/capturebhx.png/
I would like to have the Y-axis automatically scaled so that the chart looks more like this:
http://imageshack.us/photo/my-images/717/capture2wl.png/
I think org.jfree.chart.axis.NumberAxis.configure()
will do this, but I'm not sure. I can't seem to find a way to tie my JFreeChart
object, or ChartPanel
object to this NumberAxis
object. Please help me, I am lost and have been looking for a long time to try and tie these objects together. Or, if you can find another way, that'd be great too!
Some code:
...
private DefaultHighLowDataset dataset;
private JFreeChart chart;
private ChartPanel chart_panel;
...
// creates dataset, then chart from dataset, then chart_panel from chart
dataset = new DefaultHighLowDataset("", date, high, low, open, close, volume);
chart = ChartFactory.createCandlestickChart("Blank", "Time", "Price", dataset, false);
chart_panel = new ChartPanel(chart); // what you see in the images
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请务必< code>setAutoRangeInincludesZero(false) 或“轴范围……强制包含零。”
附录:
您可能需要查看
org.jfree.chart.demo
和 此处。如果这是未知领域,我会推荐JFreeChart开发者指南†。†免责声明:不隶属于 Object Refinery Limited;只是一个满意的客户和非常小的贡献者。
Be sure to
setAutoRangeIncludesZero(false)
or "the axis range…is forced to include zero."Addendum:
You may want to look into the examples in
org.jfree.chart.demo
and here. If this is terra incognita, I'd recommend The JFreeChart Developer Guide†.†Disclaimer: Not affiliated with Object Refinery Limited; just a satisfied customer and very minor contributor.
我是这样做的:
我使用这些函数计算最低低点和最低高点
这似乎给了我一个非常好的烛台图,它很好地利用了 Y 轴范围。希望这有帮助。
I did it like this:
I calculate the lowest low and lowest high using these functions
This seems to give me a very nice candlestick chart that makes good use of the Y-axis range. Hope this helps.