0
我想繪製一些垂直線來跟蹤任務,如下圖中的紅線所示。我相信可以使用甘特渲染器繪製線條。Jfreechart:在甘特圖中繪製線條箭頭
我想要的是在繪製任務期間存儲線端點的座標,然後最後在繪圖中繪製這些線。
我想知道,如果有,可以讓你對劇情畫任何東西,這是否是解決這個問題的正確方法的方法。
這裏是我的甘特碼渲染:
public class Renderer extends GanttRenderer {
private Color markerColorChannel = Color.BLUE;
private Color markerColorFunction = new Color(138,43,226);
private Color functionDurationMarkerColor = new Color(0,100,0);
private boolean functionTrace = false;
private List<ProcessorTask> listOfDrawingTask = new ArrayList<ProcessorTask>();
/**
* CONSTRUCTOR
*
* @param model
*/
public Renderer() {
}
/**
* This method is used to draw the task/subtasks for each channel or row item.
* The method is called each time the gannt chart is repainted: including zooming,
* sliding and changes to gannt chart input configurations.
*
* @param g2 The graphics device.
* @param state The renderer state.
* @param dataArea The data plot area.
* @param plot The plot.
* @param domainAxis The domain axis.
* @param rangeAxis The range axis.
* @param dataset The set of data to be drawn
* @param row The row index (zero-based).
* @param column Indicates the index of the task item to be drawn (starts from zero)
*/
// DRAW TASKS
@Override
protected void drawTasks(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis,
ValueAxis rangeAxis, GanttCategoryDataset dataset, int row, int column) {
try {
// plot.setDomainCrosshairVisible(true);
// plot.setRangeCrosshairVisible(true);
// System.out.println("ROW: " + row + " COL: " + column + " time " + System.currentTimeMillis());
/* Get the total number of subtasks in the channel or row item*/
int count = dataset.getSubIntervalCount(row, column);
/* If the item contains no subtask the count is zero. Then draw only the single task. */
if (count == 0) {
drawTask(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column);
}
/*If the item contains subtasks, loop through each of them*/
for (int subinterval = 0; subinterval < count; subinterval++) {
RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
Number subtaskStart; // start time
Number subtaskEnd; // end time
double subtaskStartTranslated;
double subtaskEndTranslated;
/* Sub task start time */
subtaskStart = dataset.getStartValue(row, column, subinterval);
if (subtaskStart == null) {
System.out.println("No starting time for subtask " + subinterval + " item " + column + " found!");
return;
}
subtaskStartTranslated = rangeAxis.valueToJava2D(subtaskStart.doubleValue(), dataArea, rangeAxisLocation);
/* Sub task end time */
subtaskEnd = dataset.getEndValue(row, column, subinterval);
if (subtaskEnd == null) {
System.out.println("No end time for subtask " + subinterval + " item " + column + " found!");
return;
}
subtaskEndTranslated = rangeAxis.valueToJava2D(subtaskEnd.doubleValue(), dataArea, rangeAxisLocation);
/*Set the rectangular bar properties*/
double rectYAxisStart;
double rectLength;
double rectBreadth;
Rectangle2D bar = null;
Number percent; // task percentage completion
rectYAxisStart = calculateBarW0(plot, plot.getOrientation(), dataArea, domainAxis, state, row, column);
rectLength = Math.abs(subtaskEndTranslated - subtaskStartTranslated);
rectBreadth = state.getBarWidth();
percent = dataset.getPercentComplete(row, column, subinterval);
/*Draw the rectangular bar*/
if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { // horizontal is applied for the ganntchart
bar = new Rectangle2D.Double(subtaskStartTranslated, rectYAxisStart, rectLength, rectBreadth);
} else if (plot.getOrientation() == PlotOrientation.VERTICAL) {
bar = new Rectangle2D.Double(rectYAxisStart, subtaskStartTranslated, rectBreadth, rectLength);
}
/*Drawing the task completion bar in the subtask bar:
* This feature is currently not needed in the gantt chart*/
/* Painting the task/subtask */
Paint seriesPaint = getItemPaint(row, column, subinterval);
g2.setPaint(seriesPaint);
g2.fill(bar);
if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
g2.setStroke(getItemStroke(row, column));
g2.setPaint(getItemOutlinePaint(row, column));
g2.draw(bar);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* This method is used to paint the subtasks of a channel or row item
* @param row
* @param col Index of the channel or the row item
* @param subinterval Index of the subtask
* @return Paint Item
*/
private Paint getItemPaint(int row, int col, int subinterval) {
return this.listOfDrawingTask.get(col).getSubTaskColorList().get(subinterval);
}
}
更新:
看來,LineAnnotations是落實行的最好方法。 Link1
上使用'CategoryLineAnnotation'同意;順便說一句,你可以[回答你自己的問題](http://meta.stackoverflow.com/q/17463/163188)。 – trashgod 2015-02-23 16:54:24