在JFreeChart堆叠的水平条形图中出现错误。

huangapple go评论104阅读模式
英文:

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);

在JFreeChart堆叠的水平条形图中出现错误。

英文:

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:

在JFreeChart堆叠的水平条形图中出现错误。

答案1

得分: 1

你的数据集有两个系列,每个系列都有一个不同的行键;但它有五个不同的类别,每个类别都有五个不同的列键。你可能希望有两个系列,_每个_系列都有自己独特的列键集。

在JFreeChart堆叠的水平条形图中出现错误。

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.

在JFreeChart堆叠的水平条形图中出现错误。

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);

huangapple
  • 本文由 发表于 2020年8月31日 17:45:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/63668455.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定