JFreeChart显示三个点(...)代替X轴上的值 [英] JFreeChart displaying three dots (...) in place of the values on the X axis
问题描述
我试图绘制一个简单的折线图,并且几乎一切都很好,我在数据集中填充了一个简单的代码,如下所示:
I am trying to plot a simple line chart and almost everything is fine, I am populating my dataset with a simple code like this:
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(-10 , "S21" , "1000" );
dataset.addValue(-20 , "S21" , "1001" );
dataset.addValue(-25 , "S21" , "1002" );
dataset.addValue(-30 , "S21" , "1003" );
dataset.addValue(-25 , "S21" , "1004" );
...
然后我创建一个折线图:
then I create a line chart:
lineChart = ChartFactory.createLineChart(
"S21",
"Frequency (MHz)",
"Value (db)",
dataset,
PlotOrientation.VERTICAL,
true,
true,
false);
,我在X轴上的值为1000 1001 1002 ...等.无论如何,我注意到,如果再添加一些点,则jfreechart在x轴上没有足够的空间,并显示三个点(...). )代替值.这很奇怪,我想获得尽可能多的积分(例如1000, 分辨率),但标签仅针对这些点的子集显示,因此我不会用完od空间:
and I have on the X axis the values 1000 1001 1002 ... etc. Anyway I noticed that, if I add some more points, jfreechart does not have enough space on the x axis and displays three dots (...) in the place of the values. This is pretty weird, I would like to have as many points as I like (e.g. 1000, to have a good resolution) but the labels shown only for a subset of these points, so I do not run out od space:
例如点:1000、1001、1002,...,2000(1000点)
E.g. points: 1000, 1001, 1002, ..., 2000 (1000 points)
标签:1000、1100、1200,...,1900、2000(10个标签)
Labels: 1000, 1100, 1200, ..., 1900, 2000 (10 labels)
有可能吗?我在网上寻找解决方案,但没有发现任何有用的方法.
Is it possible? I looked for a solution on the net, but didn't find anything useful.
推荐答案
您可能必须结合几种方法:
You may have to combine several approaches:
-
按建议在此处更改
CategoryLabelPositions
.
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(
CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0));
按照建议的此处调整图表的大小.
Adjust the chart's size, as suggested here.
ChartPanel piePanel = new ChartPanel(lineChart) {
@Override
public Dimension getPreferredSize() {
return new Dimension(640, 480);
}
};
(可选),根据类别的数量,使用SlidingCategoryDataset
,如此处所示.
Optionally, depending on the number of categories, use a SlidingCategoryDataset
, as suggested here.
(可选)如果类别构成一个连续域,请切换到XY图,例如ChartFactory.createXYLineChart()
.
Optionally, if the categories form a continuous domain, switch to an XY plot, e.g. ChartFactory.createXYLineChart()
.
这篇关于JFreeChart显示三个点(...)代替X轴上的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!