0

I was able to make a Gantt Chart in JavaFX using this answer- Gantt chart from scratch.

Also i was able to add a DateAxis by using this-http://myjavafx.blogspot.com.by/2013/09/javafx-charts-display-date-values-on.html

But right now it is unusable, because current Gantt chart does not handle "length" as a date. So it draws the beginning of the the chart perfectly accurately, but the end of the chart can be anywhere, and if you resize the window with the chart, the end will be even more random.

I am adding new chart with .add(new XYChart.Data(job.getTime(), machine, new ExtraData( timeLength, "status-red"))

where "timeLength" i set as number of milliseconds. But basicly that does not work, and it can only receive long.Also i cannot use JfreeChart, because i cannot add it FXML which i use.

So how can i get accurate both beginning and the end of each chart?

Thank you.

Community
  • 1
  • 1
user2882440
  • 1
  • 1
  • 5

1 Answers1

0

Add the following function to DateAxis class to calculate the scale factor from milliseconds to visual units.

/**
 * @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;
}

Test results

    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")));

screenshot 1

Shan
  • 56
  • 4