为什么要这段代码:
DefaultCategoryDataset datasetE = new DefaultCategoryDataset();
datasetE.addValue(0.5, "HOLDING", "NOME 1");
datasetE.addValue(0.7, "HOLDING", "NOME 2");
datasetE.addValue(0.1, "HEATING", "NOME 3");
datasetE.addValue(0.5, "HEATING", "NOME 4");
datasetE.addValue(0.8, "HEATING", "NOME 5");
JFreeChart jfreechart = ChartFactory.createStackedBarChart("Stacked Bar Chart Demo 1", "Category", "Value", datasetE, PlotOrientation.VERTICAL, true, true, false);
jfreechart.setBackgroundPaint(Color.white);
CategoryPlot categoryplot = (CategoryPlot)jfreechart.getPlot();
categoryplot.setBackgroundPaint(Color.lightGray);
categoryplot.setRangeGridlinePaint(Color.white);
StackedBarRenderer stackedbarrenderer = (StackedBarRenderer)categoryplot.getRenderer();
stackedbarrenderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator());
stackedbarrenderer.setSeriesVisible(0, true);
ChartPanel CPProgesterona = new ChartPanel(jfreechart,400,80,400,80,400,80,false,false,false,false,false,false); panel2.add(CPProgesterona,BorderLayout.NORTH);
返回此:
答案 0 :(得分:1)
您的数据集有两个系列,每个系列都有一个不同的行键;但它有五个不同的类别,每个类别都有五个不同的列键之一。您可能想要两个系列,每个每个具有自己的一组不同的列键。
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(0.5, "HOLDING", "NAME 1");
dataset.addValue(0.7, "HOLDING", "NAME 2");
dataset.addValue(0.1, "HEATING", "NAME 1");
dataset.addValue(0.5, "HEATING", "NAME 2");
dataset.addValue(0.8, "HEATING", "NAME 3");
JFreeChart jfreechart = ChartFactory.createStackedBarChart(
"Stacked Bar Chart", "Category", "Value", dataset,
PlotOrientation.HORIZONTAL, true, true, false);
CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
categoryplot.setBackgroundPaint(Color.lightGray);
categoryplot.setRangeGridlinePaint(Color.white);
StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
stackedbarrenderer.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator());
stackedbarrenderer.setDefaultItemLabelsVisible(true);