英文:
Error in JFreeChart stacked horizontal bar chart
问题
DefaultCategoryDataset datasetE = new DefaultCategoryDataset();
datasetE.addValue(0.5, "持有", "名称 1");
datasetE.addValue(0.7, "持有", "名称 2");
datasetE.addValue(0.1, "加热", "名称 3");
datasetE.addValue(0.5, "加热", "名称 4");
datasetE.addValue(0.8, "加热", "名称 5");
JFreeChart jfreechart = ChartFactory.createStackedBarChart("堆叠柱状图示例 1", "类别", "数值", 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);
英文:
Why does this code:
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);
return this:
答案1
得分: 1
你的数据集有两个系列,每个系列都有一个不同的行键;但它有五个不同的类别,每个类别都有五个不同的列键。你可能希望有两个系列,_每个_系列都有自己独特的列键集。
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(0.5, "持有", "名称 1");
dataset.addValue(0.7, "持有", "名称 2");
dataset.addValue(0.1, "加热", "名称 1");
dataset.addValue(0.5, "加热", "名称 2");
dataset.addValue(0.8, "加热", "名称 3");
JFreeChart jfreechart = ChartFactory.createStackedBarChart(
"堆叠条形图", "类别", "值", 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);
英文:
Your dataset has two series, each with a distinct row key; but it has five distinct categories, each with one of five distinct column keys. You probably want two series, each having its own set of distinct column keys.
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论