Jfreechart:在x轴上显示几天的值 [英] Jfreechart: Display weeks on x axis for value of days
问题描述
我使用JFreeChart来显示每个月的每一天的值。
现在我想让我的X轴显示一个月内的几周而不是几天。
此刻,我的图的值在y轴上是双倍,在x轴上是int。
时间戳ts = a.getTimestamp();
Double val = a.getVal();
series1.add(ts.getDate(),val);
我使用
plot.getDomainAxis()。setRange(0,31);
将日期的范围设置为一个月,
xax.setTickUnit (新的NumberTickUnit(7));
为x轴在正确的位置显示刻度。而不是显示天(0,7,14,21,28),我希望他们是星期(0,1,2,3,4)。
是这甚至可能,我将如何能够做到这一点?
您应该使用 DateAxis
为您的时间轴,如 ChartFactory.createTimeSeriesChart()
。然后你可以使用 setDateFormatOverride()
,就像他们在这里展示这里一样,和 SimpleDateFormat $
JFreeChart chart = ChartFactory.createTimeSeriesChart(...);
DateAxis axis =(DateAxis)chart.getXYPlot()。getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat(W));
I am using JFreeChart to display a value for each day of a month. Now I want to have my x-axis display the weeks in a month instead of the days. At the moment the values for my graph are double on the y-axis and int on the x axis.
Timestamp ts = a.getTimestamp();
Double val = a.getVal();
series1.add(ts.getDate(), val);
I am using
plot.getDomainAxis().setRange(0, 31);
to set the range for the days to one month and
xax.setTickUnit(new NumberTickUnit(7));
for the x-axis to display the ticks at the right position. Instead of displaying the days (0, 7, 14, 21, 28) i want them to be weeks (0, 1, 2, 3, 4).
Is that even possible, and how would I be able to do that?
You should use a DateAxis
for your time axis, like ChartFactory.createTimeSeriesChart()
does. Then you can use setDateFormatOverride()
, like they show here, and the SimpleDateFormat
for "week in month."
JFreeChart chart = ChartFactory.createTimeSeriesChart(…);
DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("W"));
这篇关于Jfreechart:在x轴上显示几天的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!