Java JFreeChart类别步骤图表横向(图像到展望) [英] Java JFreeChart Category Step Chart horizontal (image to explane)
问题描述
i需要以下类型的图表:
它应该是一个步进折线图,纵轴上有类别,如下:
i need the following type of chart:
It should be a "steped" line chart with categories on the vertical axis, like this:
我发现这个类别步骤图表的例子,但它的方向是不正确的我的目的。
I found this example of an Category Step Chart, but it the orientation is not right for my purpose.
我到目前为止是这个,但是你可以看到红线不适合图表的方向(应该是水平的):
All i have done so far is this, but as you can see the red line does not fit to the orientation of the chart(should be horizontal):
对应的代码:
DefaultCategoryDataset ds = new DefaultCategoryDataset();
// create dataset
for (int k = 0; k < ffCount; k++) {
StateSignal ss1 = (StateSignal) this.ffDSet.getFframes().get(k).getSignals().get(i);
ds.setValue((double) k + 1, ss1.getName(), ss1.getStates().get(0).getStatus());
}
CategoryStepRenderer categorysteprenderer = new CategoryStepRenderer(false);
categorysteprenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
CategoryAxis categoryaxis = new CategoryAxis("Category");
NumberAxis numberaxis = new NumberAxis("Value");
CategoryPlot categoryplot = new CategoryPlot(ds, categoryaxis, numberaxis, categorysteprenderer);
categoryplot.setRangePannable(true);
categoryplot.setOrientation(PlotOrientation.HORIZONTAL);
chart = new JFreeChart("test", null, categoryplot, true);
我无法使用它。任何想法?
I don´t get it to work. Any ideas?
提前感谢!
推荐答案
您需要使用具有 XYStepRenderer
和 SymbolAxis
的标准XYLineChart来替换默认范围轴,而不是 CategoryStepRenderer
和水平绘图方向
It looks like you need to use a standard XYLineChart with a XYStepRenderer
and a SymbolAxis
to replace the default Range Axis rather than a CategoryStepRenderer
and a horizontal plot orientation
如果您将状态A和B与数值1和2关联,这样的图表:
If you associate Status A and B with a numerical value say 1 and 2 you can create a chart like this:
使用这个 XYStepRenderer
XYStepRenderer renderer = new XYStepRenderer();
renderer.setBaseShapesVisible(true);
renderer.setSeriesStroke(0, new BasicStroke(2.0f));
renderer.setSeriesStroke(1, new BasicStroke(2.0f));
renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
renderer.setDefaultEntityRadius(6);
plot.setRenderer(renderer);
和符号轴
String[] grade = new String[3];
grade[0] = "";
grade[1] = "Status A";
grade[2] = "Status B";
SymbolAxis rangeAxis = new SymbolAxis("", grade);
rangeAxis.setTickUnit(new NumberTickUnit(1));
rangeAxis.setRange(0,3);
plot.setRangeAxis(rangeAxis);
在此示例中, SymbolAxis
Axis中的每个值的标签
In this example the SymbolAxis
provides an alternative label for each value in the Axis
这篇关于Java JFreeChart类别步骤图表横向(图像到展望)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!