【问题标题】:Adding DateAxis to gantt Chart Javafx将 DateAxis 添加到甘特图 Javafx
【发布时间】:2016-07-09 02:02:54
【问题描述】:
【问题讨论】:
标签:
java
javafx
charts
axis
gantt-chart
【解决方案1】:
将以下函数添加到 DateAxis 类中,以计算从毫秒到视觉单位的比例因子。
/**
* @return The scale factor from milliseconds to visual units
*/
public double getScale(){
final double length = getSide().isHorizontal() ? getWidth() : getHeight();
// Get the difference between the max and min date.
double diff = currentUpperBound.get() - currentLowerBound.get();
// Get the actual range of the visible area.
// The minimal date should start at the zero position, that's why we subtract it.
double range = length - getZeroPosition();
return length/diff;
}
测试结果
Date startDate=new Date();
long duration = 1000*60*1;//1 hour in milliseconds
series1.getData().add(new XYChart.Data(startDate, machine, new ExtraData(duration, "status-green")));
startDate = new Date(startDate.getTime()+duration);
duration = 1000*60*1;//2 hours in milliseconds
series1.getData().add(new XYChart.Data(startDate, machine, new ExtraData(duration, "status-red")));
截图1