jfreechart柱图总结

关于条形图的一个总结:

首先使用的是dataset数据源的类是:DefaultCategoryDataset()
1
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
2
 
3
dataset.addValue(1.0, series1, category1);
4
dataset.addValue(4.0, series1, category2);
5
dataset.addValue(3.0, series1, category3);
6
dataset.addValue(5.0, series1, category4);
7
dataset.addValue(5.0, series1, category5);
使用的JFreeChart对象是:ChartFactory.createBarChart()
01
// create the chart...
02
        JFreeChart chart = ChartFactory.createBarChart(
03
            "Bar Chart Demo",         // chart title
04
            "Category",               // domain axis label
05
            "Value",                  // range axis label
06
            dataset,                  // data
07
            PlotOrientation.VERTICAL, // orientation
08
            true,                     // include legend
09
            true,                     // include tooltips?
10
            false                     // URLs?
11
        );
对于条形图的图表的定制
所涉及的有图表区域的处理,轴的处理,对于每一个柱状的处理

对于图表区域的处理的对象:CategoryPlot()
1
CategoryPlot plot = (CategoryPlot) chart.getPlot();
扩展: CategoryPlot类

01
void setDataset(CategoryDataset dataset) 数据区的2维数据表
02
void setColumnRenderingOrder(SortOrder order) 数据分类的排序方式
03
void setAxisOffset(Spacer offset) 坐标轴到数据区的间距
04
void setOrientation(PlotOrientation orientation) 数据区的方向(PlotOrientation.HORIZONTAL或PlotOrientation.VERTICAL)
05
void setDomainAxis(CategoryAxis axis) 数据区的分类轴
06
void setDomainAxisLocation(AxisLocation location) 分类轴的位置(参数常量在org.jfree.chart.axis.AxisLocation类中定义)
07
void setDomainGridlinesVisible(boolean visible) 分类轴网格是否可见
08
void setDomainGridlinePaint(Paint paint) 分类轴网格线条颜色
09
void setDomainGridlineStroke(Stroke stroke) 分类轴网格线条笔触
10
void setRangeAxis(ValueAxis axis) 数据区的数据轴
11
void setRangeAxisLocation(AxisLocation location) 数据轴的位置(参数常量在org.jfree.chart.axis.AxisLocation类中定义)
12
void setRangeGridlinesVisible(boolean visible) 数据轴网格是否可见
13
void setRangeGridlinePaint(Paint paint) 数据轴网格线条颜色
14
void setRangeGridlineStroke(Stroke stroke) 数据轴网格线条笔触
15
void setRenderer(CategoryItemRenderer renderer) 数据区的表示者(详见Renderer组)
16
void addAnnotation(CategoryAnnotation annotation) 给数据区加一个注释
17
void addRangeMarker(Marker marker,Layer layer) 给数据区加一个数值范围区域
同样的,由于 CategoryPlot类是Plot的子类,所以对于Plot类所拥有的方法, CategoryPlot类是都具有的,在这就不帖Plot的代码了。
对于图表轴的对象是 CategoryAxis类和ValueAxis()类(或其子类)
其中CategoryAxis类主要是针对于Y轴的;


1
CategoryAxis domainAxis = plot.getDomainAxis();
而 ValueAxis()主要是针对于X轴的;

1
BarRenderer renderer = (BarRenderer) plot.getRenderer();
扩展: CategoryAxis类的方法

1
void setCategoryMargin(double margin) 分类轴边距
2
void setLowerMargin(double margin) 分类轴下(左)边距
3
void setUpperMargin(double margin) 分类轴上(右)边距
4
void setVerticalCategoryLabels(boolean flag) 分类轴标题是否旋转到垂直
5
void setMaxCategoryLabelWidthRatio(float ratio) 分类轴分类标签的最大宽度
扩展: ValueAxis()类的方法

01
void setAutoRange(boolean auto) 自动设置数据轴数据范围
02
void setAutoRangeMinimumSize(double size) 自动设置数据轴数据范围时数据范围的最小跨度
03
void setAutoTickUnitSelection(boolean flag) 数据轴的数据标签是否自动确定(默认为true)
04
void setFixedAutoRange(double length) 数据轴固定数据范围(设置100的话就是显示MAXVALUE到MAXVALUE-100那段数据范围)
05
void setInverted(boolean flag) 数据轴是否反向(默认为false)
06
void setLowerMargin(double margin) 数据轴下(左)边距
07
void setUpperMargin(double margin) 数据轴上(右)边距
08
void setLowerBound(double min) 数据轴上的显示最小值
09
void setUpperBound(double max) 数据轴上的显示最大值
10
void setPositiveArrowVisible(boolean visible) 是否显示正向箭头(3D轴无效)
11
void setNegativeArrowVisible(boolean visible) 是否显示反向箭头(3D轴无效)
12
void setVerticalTickLabels(boolean flag) 数据轴数据标签是否旋转到垂直
13
void setStandardTickUnits(TickUnitSource source) 数据轴的数据标签(可以只显示整数标签,需要将AutoTickUnitSelection设false)
同样的,由于两者都是Axis的子类,所以都拥有Axis的方法,之前我也帖过了Axis的代码了,在这就不帖了。
对于每一个条形的属性的对象:BarRenderer

1
BarRenderer renderer = (BarRenderer) plot.getRenderer();
扩展:BarRenderer类的方法


1
void setDrawBarOutline(boolean draw)是否画图形边框
2
void setItemMargin(double percent)每个BAR之间的间隔
3
void setMaxBarWidth(double percent)每个BAR的最大宽度
4
void setMinimumBarLength(double min)最短的BAR长度,避免数值太小而显示不出
5
void setPositiveItemLabelPositionFallback(ItemLabelPosition position)无法在BAR中显示的正数标签位置
6
void setNegativeItemLabelPositionFallback(ItemLabelPosition position)无法在BAR中显示的负数标签位置
PS:由于 BarRenderer是AbstractCategoryItemRenderer类的子类,所以继承了他的所有方法
扩展:AbstractCategoryItemRenderer类的方法


1
void setLabelGenerator(CategoryLabelGenerator generator)数据标签的格式
2
void setToolTipGenerator(CategoryToolTipGenerator generator)MAP中鼠标移上的显示格式
3
void setItemURLGenerator(CategoryURLGenerator generator)MAP中钻取链接格式
4
void setSeriesLabelGenerator(int series,CategoryLabelGenerator generator)指定分类的数据标签的格式
5
void setSeriesToolTipGenerator(int series,CategoryToolTipGenerator generator)指定分类的MAP中鼠标移上的显示格式
6
void setSeriesItemURLGenerator(int series,CategoryURLGenerator generator)指定分类的MAP中钻取链接格式
PPS:对于 AbstractCategoryItemRenderer类是AbstractRenderer类的子类,所有也继承了他的所有方法

view sourceprint?
01
<strong>void setItemLabelAnchorOffset(double offset)数据标签的与数据点的偏移
02
void setItemLabelsVisible(boolean visible)数据标签是否可见
03
void setItemLabelFont(Font font)数据标签的字体
04
void setItemLabelPaint(Paint paint)数据标签的字体颜色
05
void setItemLabelPosition(ItemLabelPosition position)数据标签位置
06
void setPositiveItemLabelPosition(ItemLabelPosition position)正数标签位置
07
void setNegativeItemLabelPosition(ItemLabelPosition position)负数标签位置
08
void setOutLinePaint(Paint paint)图形边框的线条颜色
09
void setOutLineStroke(Stroke stroke)图形边框的线条笔触
10
void setPaint(Paint paint)所有分类图形的颜色
11
void setShape(Shape shape)所有分类图形的形状(如折线图的点)
12
void setStroke(Stroke stroke)所有分类图形的笔触(如折线图的线)
13
void setSeriesItemLabelsVisible(int series,boolean visible)指定分类的数据标签是否可见
14
void setSeriesItemLabelFont(int series,Font font)指定分类的数据标签的字体
15
void setSeriesItemLabelPaint(int series,Paint paint)指定分类的数据标签的字体颜色
16
void setSeriesItemLabelPosition(int series,ItemLabelPosition position)数据标签位置
17
void setSeriesPositiveItemLabelPosition(int series,ItemLabelPosition position)正数标签位置
18
void setSeriesNegativeItemLabelPosition(int series,ItemLabelPosition position)负数标签位置
19
void setSeriesOutLinePaint(int series,Paint paint)指定分类的图形边框的线条颜色
20
void setSeriesOutLineStroke(int series,Stroke stroke)指定分类的图形边框的线条笔触
21
void setSeriesPaint(int series,Paint paint)指定分类图形的颜色
22
void setSeriesShape(int series,Shape shape)指定分类图形的形状(如折线图的点)
23
void setSeriesStroke(int series,Stroke stroke)指定分类图形的笔触(如折线图的线)</strong>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值