我目前使用JFreeChart遇到了问题。我需要两个相关的域轴,例如:
|
|
|
|
|
|
_________ _________ __________(第一个轴)
8:00 - 9:00 9:01 - 10:00 10:01 - 11:00
|
______ ______(第二个轴在第一个轴下面)
Phase 1 Phase 2
也就是说,Phase 1实际上对应于8:00到8:45(在第一个轴上),而Phase 2对应于8:46到9:20。
以下是我用来解决问题的代码:
也就是说,Phase 1实际上对应于8:00到8:45(在第一个轴上),而Phase 2对应于8:46到9:20。
以下是我用来解决问题的代码:
private ChartPanel createChart(CategoryDataset dataset, CategoryDataset phaseDataset){
JFreeChart chart = ChartFactory.createBarChart(
"",
"",
"Numbers",
dataset,
PlotOrientation.Vertical,
true,
true,
false);
CategoryPlot plot = chart.getCategoryPlot();
NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis();
rangeAxis.setStandTickUnits(NumberAxis.createIntegerTickUnits());
CategoryAxis domainAxis = plot.getDomainAxis();
// some paint settings to be done to domainAxis
CategoryAxis axis2 = new CategoryAxis()
plot.setDomainAxis(1, axis2);
plot.setDataset(1, phaseDataset);
plot.mapDatasetToRangeAxis(1,1);
plot.setDomainAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
ChartPanel panel = new ChartPanel(chart);
return panel;
}
我的第二个轴(用于相位)的刻度标签似乎在顶部而不是底部。
我该如何实现这一点?抱歉画得很烂,无法附加图像...
另一个问题 - 我如何设置CategoryAxis的范围?我希望所有类别都出现在我的图表中,但如果该类别中没有数据,则该类别将不会出现?
回到设计基础知识?我是否为此使用了正确的域轴?
@EDIT 我注意到我添加的第二个轴无法显示刻度,第二组数据集实际上出现在第一个轴上...