JFreeChart ライブラリは初めてです。現在、3D 棒グラフをいじっていますが、生成されたそれぞれの 3D 棒を異なる色にすることは可能でしょうか? 以下に示すように、現在それらはすべて黄色です。
色を変更するためにオーバーライドできるものはありますか?
ありがとう。
コード:
import java.awt.Dimension;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class jfree extends ApplicationFrame
{
{
// set a theme using the new shadow generator feature available in
// 1.0.14 - for backwards compatibility it is not enabled by default
ChartFactory.setChartTheme(StandardChartTheme.createDarknessTheme());
}
public jfree(String s)
{
super(s);
JPanel jpanel = createDemoPanel();
jpanel.setPreferredSize(new Dimension(500, 270));
setContentPane(jpanel);
}
private static CategoryDataset createDataset()
{
DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
defaultcategorydataset.addValue(25D, "Series 1", "Pipe Stricking");
defaultcategorydataset.addValue(17D, "Series 1", "Lost Circulation");
defaultcategorydataset.addValue(34D, "Series 1", "Hole Deviation");
defaultcategorydataset.addValue(12D, "Series 1", "Kick Blowout");
defaultcategorydataset.addValue(54D, "Series 1", "Formation Change");
defaultcategorydataset.addValue(10D, "Series 1", "Borehole Instability");
defaultcategorydataset.addValue(19D, "Series 1", "Cavings/Pack-offs");
return defaultcategorydataset;
}
private static JFreeChart createChart(CategoryDataset categorydataset)
{
JFreeChart jfreechart = ChartFactory.createBarChart3D("IPS", "", "Value", categorydataset, PlotOrientation.VERTICAL, false, false, false);
CategoryPlot categoryplot = (CategoryPlot)jfreechart.getPlot();
CategoryAxis categoryaxis = categoryplot.getDomainAxis();
categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.2D));
CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
categoryitemrenderer.setBaseItemLabelsVisible(true);
BarRenderer barrenderer = (BarRenderer)categoryitemrenderer;
barrenderer.setItemMargin(200D);
return jfreechart;
}
public static JPanel createDemoPanel()
{
JFreeChart jfreechart = createChart(createDataset());
return new ChartPanel(jfreechart);
}
public static void main(String args[])
{
jfree jfree = new jfree("3D Bar Chart Demo 3");
jfree.pack();
RefineryUtilities.centerFrameOnScreen(jfree);
jfree.setVisible(true);
}
}