1
這裏紅色柱狀圖在前面,中間和綠色在後面藍色柱狀圖。所以大部分的綠色直方圖都無法看到。懸停鼠標或任何其他選項以查看綠色和藍色直方圖時,是否有任何選項在顏色之間切換?
下面是代碼
public class HistogramFrame extends JFrame {
static double[] red;
static double[] green;
static double[] blue;
public HistogramFrame(String title, double[] red, double[] green, double[] blue) {
super(title);
HistogramFrame.red = red;
HistogramFrame.green = green;
HistogramFrame.blue = blue;
JFreeChart jfreechart = ChartFactory.createHistogram("Histograms combination red,blue,green", null, null, createDataset(), PlotOrientation.VERTICAL, true, true, false);
XYPlot xyplot = (XYPlot) jfreechart.getPlot();
xyplot.setForegroundAlpha(0.85F);
XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
xybarrenderer.setDrawBarOutline(false);
JPanel jpanel = new ChartPanel(jfreechart);
jpanel.setPreferredSize(new Dimension(1000, 600));
setContentPane(jpanel);
}
private static IntervalXYDataset createDataset() {
HistogramDataset histogramdataset = new HistogramDataset();
histogramdataset.addSeries("Red histogram", red, 256);
histogramdataset.addSeries("Blue histogram", blue, 256);
histogramdataset.addSeries("Green histogram", green, 256);
return histogramdataset;
}
}
使用單獨的半透明顏色的一種方法是檢查[這裏](http://stackoverflow.com/a/28519356/230513)。 – trashgod
也嘗試一個'StandardBarPainter',建議[這裏](http://stackoverflow.com/a/7092567/230513)。 – trashgod
@trashgod謝謝。 DefaultDrawingSupplier給了半透明的顏色並修復了問題 – Dilushan