这是代码:
public static void drawSecLineChart(String seccode,String secname) throws IOException, ParseException {
TimeSeries ts =new TimeSeries(seccode, Day.class);
//(convert(varchar(7),getDate())+convert(varchar(5),datepart(year,getDate())-2))
List<SecQuote>list =em.findBySql(SecQuote.class, "select * from SecQuote");
for(SecQuote sq :list){
ts.add(new Day(sq.getId()), sq.getSecQClose());
}
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(ts);
System.out.println(dataset.getDomainUpperBound(true)+"------------:"+dataset.getDomainLowerBound(true));
JFreeChart chart = ChartFactory.createTimeSeriesChart(
secname,
//lt.XTitle,
"",
//lt.YTitle,
"",
dataset, //得到结果集!
false, // 是否显示图例(对于简单的柱状图必须是false)
true, // 是否生成工具
false // 是否生成URL链接
);
//true,false,false生成底部的标题"-600839.shse" //false,true,false不生成相对应的文件。
saveChart2(chart, seccode,secname);
}
//------------------
public static void saveChart2(JFreeChart chart, String names,String secname)throws IOException, ParseException {
chart.setBackgroundPaint(Color.black);
chart.setPadding(new RectangleInsets(3.0,3.0,3.0,10.0));//调整和xy的距离
// LegendTitle legend = chart.getLegend(0); // 修改图例的字体
// legend.setItemFont(new Font("幼圆", Font.BOLD, 14)); // 取得时间顺序图的Plot对象
// legend.setItemPaint(Color.white);
// legend.setBackgroundPaint(Color.black);
XYPlot plot = (XYPlot) chart.getPlot(); // 取得横轴
Image image = null;
image = ImageIO.read(new File(Messages.getString("vvbackimage1")));
plot.setBackgroundImage(image);
//使用这个方法显示值
XYItemRenderer xrend = (XYItemRenderer)plot.getRenderer();
//这里显示折点值----------怎么控制只显示最大值和最小值了?
xrend.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
xrend.setBaseItemLabelsVisible(true);
// xrend.setBaseToolTipGenerator(generator)
//xrend.setSeriesVisible(0, null, false); //这里是设置第几个集合的数据不显示。
// xrend.setBasePositiveItemLabelPosition(position, notify)
//xrend.setBaseNegativeItemLabelPosition(new ItemLabelPosition());
xrend.setBaseItemLabelFont(new Font("Impact", Font.ITALIC, 14)); //设置折点上的值的字体
xrend.setBaseItemLabelPaint(Color.yellow);
//
DateAxis categoryAxis = (DateAxis) plot.getDomainAxis(); // 设置横轴显示标签的字体
categoryAxis.setLabelFont(new Font(Messages.getString("fonttype"), Font.ITALIC, Integer.parseInt(Messages.getString("fontsize"))));
categoryAxis.setTickLabelFont(new Font(Messages.getString("fonttype"), Font.PLAIN, Integer.parseInt(Messages.getString("fontsize"))));
categoryAxis.setPositiveArrowVisible(false);
// Color col = new Color(234,123,62);
// categoryAxis.setTickLabelPaint(col);// 横轴下的字体颜色
// categoryAxis.setLabelPaint(col);// 横轴主字体颜色
// categoryAxis.setLabelAngle(0.1);
// categoryAxis.setVerticalTickLabels(true);
Color col = new Color(234,123,62);
categoryAxis.setTickLabelPaint(col);// 横轴下的字体颜色
categoryAxis.setLabelPaint(col);// 横轴主字体颜色
categoryAxis.setUpperMargin(0.05); //右间距
//设置时间的序列
// SegmentedTimeline s = SegmentedTimeline.newMondayThroughFridayTimeline();
// List el = holidays();
// s.addExceptions(el);
// Calendar c = Calendar.getInstance();
// c.set(c.YEAR, 2006);
//
// Calendar d = Calendar.getInstance();
// Range range = new Range(c.getTimeInMillis(),d.getTimeInMillis());
// categoryAxis.setRange(range);
// categoryAxis.setAutoRange(false);
// categoryAxis.setTimeline(s);
//DateTickUnit dt = new DateTickUnit(DateTickUnit.MONTH, Integer.parseInt(Messages.getString("interval_mon2")));//,DateTickUnit.DAY,10,new SimpleDateFormat("yyyy-MM"));
DateTickUnit dt = new DateTickUnit(DateTickUnit.DAY, 120);
categoryAxis.setTickUnit(dt);
categoryAxis.setDateFormatOverride(new SimpleDateFormat("yy-MM-dd"));
// 取得纵轴
NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
// 设置纵轴显示标签的字体
//numberAxis.setLabelFont(new Font("宋体", Font.BOLD, 22));
numberAxis.setLabelFont(new Font(Messages.getString("fonttype"), Font.PLAIN, Integer.parseInt(Messages.getString("fontsize"))));
numberAxis.setTickLabelFont(new Font(Messages.getString("fonttype"), Font.PLAIN, Integer.parseInt(Messages.getString("fontsize"))));
//numberAxis.setLabelAngle(1.5);
Color col2 = new Color(80,217,209);
numberAxis.setTickLabelPaint(col2);
numberAxis.setLabelPaint(col2);
chart.getTitle().setBackgroundPaint(Color.BLACK);
chart.getTitle().setPaint(Color.orange);
//设置标题颜色
plot.setBackgroundPaint(Color.black);
plot.setWeight(10);
plot.getRenderer().setSeriesItemLabelPaint(0, col2);
plot.getRenderer().setSeriesPaint(0, col2);
plot.setOutlinePaint(Color.white);
BasicStroke bs = new BasicStroke(1);//设置边框的粗细
//设置*图的风格
plot.setOutlineStroke(bs);
plot.setDomainCrosshairPaint(Color.GREEN);
plot.setQuadrantPaint(0, Color.PINK);
plot.setDomainGridlinePaint(Color.yellow);
plot.setRangeGridlinePaint(Color.GREEN);
FileOutputStream fos = null;
String path = Messages.getString("savepath");
String name = names + ".png";
File f = new File(path + name);
if (!f.getParentFile().exists())
f.getParentFile().mkdirs();
fos = new FileOutputStream(f);// 将统计图标输出成JPG文件
ChartUtilities.writeChartAsPNG(fos, // 输出到哪个输出流
chart, // 统计图标对象
//800, // 宽
555,
//600,// 高
334,
null // ChartRenderingInfo 信息
);
fos.close();
}
8 个解决方案
#1
我觉得这种情况楼主应该看它的文档, 毕竟这个东西不是太流行, 大家都用的不多, 即使用过也没用处经验, 我也只用它来做过一个demo. 还是你自己去度doc比较好, 把它变成自己的东西.
#2
很早以前用过~! 现在都回想不起来了
感觉JFreeChart配置复杂
感觉JFreeChart配置复杂
#3
look document!
#4
package nc.ui.test.chart;
import java.awt.Dimension;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class BarChart3DDemo3 extends ApplicationFrame
{
public BarChart3DDemo3(String s)
{
super(s);
CategoryDataset categorydataset = createDataset();
JFreeChart jfreechart = createChart(categorydataset);
ChartPanel chartpanel = new ChartPanel(jfreechart);
chartpanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartpanel);
}
private static CategoryDataset createDataset()
{
DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
defaultcategorydataset.addValue(25D, "Series 1", "Category 1");
defaultcategorydataset.addValue(34D, "Series 1", "Category 2");
defaultcategorydataset.addValue(19D, "Series 2", "Category 1");
defaultcategorydataset.addValue(29D, "Series 2", "Category 2");
defaultcategorydataset.addValue(41D, "Series 3", "Category 1");
defaultcategorydataset.addValue(33D, "Series 3", "Category 2");
return defaultcategorydataset;
}
private static JFreeChart createChart(CategoryDataset categorydataset)
{
JFreeChart jfreechart = ChartFactory.createBarChart3D("3D Bar Chart Demo", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false);
CategoryPlot categoryplot = jfreechart.getCategoryPlot();
CategoryAxis categoryaxis = categoryplot.getDomainAxis();
categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D));
CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
categoryitemrenderer.setItemLabelsVisible(true);
BarRenderer barrenderer = (BarRenderer)categoryitemrenderer;
barrenderer.setItemMargin(0.20000000000000001D);
return jfreechart;
}
public static JPanel createDemoPanel()
{
JFreeChart jfreechart = createChart(createDataset());
return new ChartPanel(jfreechart);
}
public static void main(String args[])
{
BarChart3DDemo3 barchart3ddemo3 = new BarChart3DDemo3("3D Bar Chart Demo 3");
barchart3ddemo3.pack();
RefineryUtilities.centerFrameOnScreen(barchart3ddemo3);
barchart3ddemo3.setVisible(true);
}
}
试一下这个,调试过的
import java.awt.Dimension;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class BarChart3DDemo3 extends ApplicationFrame
{
public BarChart3DDemo3(String s)
{
super(s);
CategoryDataset categorydataset = createDataset();
JFreeChart jfreechart = createChart(categorydataset);
ChartPanel chartpanel = new ChartPanel(jfreechart);
chartpanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartpanel);
}
private static CategoryDataset createDataset()
{
DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
defaultcategorydataset.addValue(25D, "Series 1", "Category 1");
defaultcategorydataset.addValue(34D, "Series 1", "Category 2");
defaultcategorydataset.addValue(19D, "Series 2", "Category 1");
defaultcategorydataset.addValue(29D, "Series 2", "Category 2");
defaultcategorydataset.addValue(41D, "Series 3", "Category 1");
defaultcategorydataset.addValue(33D, "Series 3", "Category 2");
return defaultcategorydataset;
}
private static JFreeChart createChart(CategoryDataset categorydataset)
{
JFreeChart jfreechart = ChartFactory.createBarChart3D("3D Bar Chart Demo", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false);
CategoryPlot categoryplot = jfreechart.getCategoryPlot();
CategoryAxis categoryaxis = categoryplot.getDomainAxis();
categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D));
CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
categoryitemrenderer.setItemLabelsVisible(true);
BarRenderer barrenderer = (BarRenderer)categoryitemrenderer;
barrenderer.setItemMargin(0.20000000000000001D);
return jfreechart;
}
public static JPanel createDemoPanel()
{
JFreeChart jfreechart = createChart(createDataset());
return new ChartPanel(jfreechart);
}
public static void main(String args[])
{
BarChart3DDemo3 barchart3ddemo3 = new BarChart3DDemo3("3D Bar Chart Demo 3");
barchart3ddemo3.pack();
RefineryUtilities.centerFrameOnScreen(barchart3ddemo3);
barchart3ddemo3.setVisible(true);
}
}
试一下这个,调试过的
#5
package nc.ui.test.chart;
import java.awt.Dimension;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class BarChart3DDemo3 extends ApplicationFrame
{
public BarChart3DDemo3(String s)
{
super(s);
CategoryDataset categorydataset = createDataset();
JFreeChart jfreechart = createChart(categorydataset);
ChartPanel chartpanel = new ChartPanel(jfreechart);
chartpanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartpanel);
}
private static CategoryDataset createDataset()
{
DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
defaultcategorydataset.addValue(25D, "Series 1", "Category 1");
defaultcategorydataset.addValue(34D, "Series 1", "Category 2");
defaultcategorydataset.addValue(19D, "Series 2", "Category 1");
defaultcategorydataset.addValue(29D, "Series 2", "Category 2");
defaultcategorydataset.addValue(41D, "Series 3", "Category 1");
defaultcategorydataset.addValue(33D, "Series 3", "Category 2");
return defaultcategorydataset;
}
private static JFreeChart createChart(CategoryDataset categorydataset)
{
JFreeChart jfreechart = ChartFactory.createBarChart3D("3D Bar Chart Demo", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false);
CategoryPlot categoryplot = jfreechart.getCategoryPlot();
CategoryAxis categoryaxis = categoryplot.getDomainAxis();
categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D));
CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
categoryitemrenderer.setItemLabelsVisible(true);
BarRenderer barrenderer = (BarRenderer)categoryitemrenderer;
barrenderer.setItemMargin(0.20000000000000001D);
return jfreechart;
}
public static JPanel createDemoPanel()
{
JFreeChart jfreechart = createChart(createDataset());
return new ChartPanel(jfreechart);
}
public static void main(String args[])
{
BarChart3DDemo3 barchart3ddemo3 = new BarChart3DDemo3("3D Bar Chart Demo 3");
barchart3ddemo3.pack();
RefineryUtilities.centerFrameOnScreen(barchart3ddemo3);
barchart3ddemo3.setVisible(true);
}
}
试一下这个,调试过的
import java.awt.Dimension;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class BarChart3DDemo3 extends ApplicationFrame
{
public BarChart3DDemo3(String s)
{
super(s);
CategoryDataset categorydataset = createDataset();
JFreeChart jfreechart = createChart(categorydataset);
ChartPanel chartpanel = new ChartPanel(jfreechart);
chartpanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartpanel);
}
private static CategoryDataset createDataset()
{
DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
defaultcategorydataset.addValue(25D, "Series 1", "Category 1");
defaultcategorydataset.addValue(34D, "Series 1", "Category 2");
defaultcategorydataset.addValue(19D, "Series 2", "Category 1");
defaultcategorydataset.addValue(29D, "Series 2", "Category 2");
defaultcategorydataset.addValue(41D, "Series 3", "Category 1");
defaultcategorydataset.addValue(33D, "Series 3", "Category 2");
return defaultcategorydataset;
}
private static JFreeChart createChart(CategoryDataset categorydataset)
{
JFreeChart jfreechart = ChartFactory.createBarChart3D("3D Bar Chart Demo", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false);
CategoryPlot categoryplot = jfreechart.getCategoryPlot();
CategoryAxis categoryaxis = categoryplot.getDomainAxis();
categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D));
CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
categoryitemrenderer.setItemLabelsVisible(true);
BarRenderer barrenderer = (BarRenderer)categoryitemrenderer;
barrenderer.setItemMargin(0.20000000000000001D);
return jfreechart;
}
public static JPanel createDemoPanel()
{
JFreeChart jfreechart = createChart(createDataset());
return new ChartPanel(jfreechart);
}
public static void main(String args[])
{
BarChart3DDemo3 barchart3ddemo3 = new BarChart3DDemo3("3D Bar Chart Demo 3");
barchart3ddemo3.pack();
RefineryUtilities.centerFrameOnScreen(barchart3ddemo3);
barchart3ddemo3.setVisible(true);
}
}
试一下这个,调试过的
#6
有没有画折线图的例子啊.
#7
想要一个曲线的,不过得自己写了~~
#8
我知道可以设最大最小值
但是只显示这两个点没有用过啊
#1
我觉得这种情况楼主应该看它的文档, 毕竟这个东西不是太流行, 大家都用的不多, 即使用过也没用处经验, 我也只用它来做过一个demo. 还是你自己去度doc比较好, 把它变成自己的东西.
#2
很早以前用过~! 现在都回想不起来了
感觉JFreeChart配置复杂
感觉JFreeChart配置复杂
#3
look document!
#4
package nc.ui.test.chart;
import java.awt.Dimension;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class BarChart3DDemo3 extends ApplicationFrame
{
public BarChart3DDemo3(String s)
{
super(s);
CategoryDataset categorydataset = createDataset();
JFreeChart jfreechart = createChart(categorydataset);
ChartPanel chartpanel = new ChartPanel(jfreechart);
chartpanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartpanel);
}
private static CategoryDataset createDataset()
{
DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
defaultcategorydataset.addValue(25D, "Series 1", "Category 1");
defaultcategorydataset.addValue(34D, "Series 1", "Category 2");
defaultcategorydataset.addValue(19D, "Series 2", "Category 1");
defaultcategorydataset.addValue(29D, "Series 2", "Category 2");
defaultcategorydataset.addValue(41D, "Series 3", "Category 1");
defaultcategorydataset.addValue(33D, "Series 3", "Category 2");
return defaultcategorydataset;
}
private static JFreeChart createChart(CategoryDataset categorydataset)
{
JFreeChart jfreechart = ChartFactory.createBarChart3D("3D Bar Chart Demo", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false);
CategoryPlot categoryplot = jfreechart.getCategoryPlot();
CategoryAxis categoryaxis = categoryplot.getDomainAxis();
categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D));
CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
categoryitemrenderer.setItemLabelsVisible(true);
BarRenderer barrenderer = (BarRenderer)categoryitemrenderer;
barrenderer.setItemMargin(0.20000000000000001D);
return jfreechart;
}
public static JPanel createDemoPanel()
{
JFreeChart jfreechart = createChart(createDataset());
return new ChartPanel(jfreechart);
}
public static void main(String args[])
{
BarChart3DDemo3 barchart3ddemo3 = new BarChart3DDemo3("3D Bar Chart Demo 3");
barchart3ddemo3.pack();
RefineryUtilities.centerFrameOnScreen(barchart3ddemo3);
barchart3ddemo3.setVisible(true);
}
}
试一下这个,调试过的
import java.awt.Dimension;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class BarChart3DDemo3 extends ApplicationFrame
{
public BarChart3DDemo3(String s)
{
super(s);
CategoryDataset categorydataset = createDataset();
JFreeChart jfreechart = createChart(categorydataset);
ChartPanel chartpanel = new ChartPanel(jfreechart);
chartpanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartpanel);
}
private static CategoryDataset createDataset()
{
DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
defaultcategorydataset.addValue(25D, "Series 1", "Category 1");
defaultcategorydataset.addValue(34D, "Series 1", "Category 2");
defaultcategorydataset.addValue(19D, "Series 2", "Category 1");
defaultcategorydataset.addValue(29D, "Series 2", "Category 2");
defaultcategorydataset.addValue(41D, "Series 3", "Category 1");
defaultcategorydataset.addValue(33D, "Series 3", "Category 2");
return defaultcategorydataset;
}
private static JFreeChart createChart(CategoryDataset categorydataset)
{
JFreeChart jfreechart = ChartFactory.createBarChart3D("3D Bar Chart Demo", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false);
CategoryPlot categoryplot = jfreechart.getCategoryPlot();
CategoryAxis categoryaxis = categoryplot.getDomainAxis();
categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D));
CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
categoryitemrenderer.setItemLabelsVisible(true);
BarRenderer barrenderer = (BarRenderer)categoryitemrenderer;
barrenderer.setItemMargin(0.20000000000000001D);
return jfreechart;
}
public static JPanel createDemoPanel()
{
JFreeChart jfreechart = createChart(createDataset());
return new ChartPanel(jfreechart);
}
public static void main(String args[])
{
BarChart3DDemo3 barchart3ddemo3 = new BarChart3DDemo3("3D Bar Chart Demo 3");
barchart3ddemo3.pack();
RefineryUtilities.centerFrameOnScreen(barchart3ddemo3);
barchart3ddemo3.setVisible(true);
}
}
试一下这个,调试过的
#5
package nc.ui.test.chart;
import java.awt.Dimension;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class BarChart3DDemo3 extends ApplicationFrame
{
public BarChart3DDemo3(String s)
{
super(s);
CategoryDataset categorydataset = createDataset();
JFreeChart jfreechart = createChart(categorydataset);
ChartPanel chartpanel = new ChartPanel(jfreechart);
chartpanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartpanel);
}
private static CategoryDataset createDataset()
{
DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
defaultcategorydataset.addValue(25D, "Series 1", "Category 1");
defaultcategorydataset.addValue(34D, "Series 1", "Category 2");
defaultcategorydataset.addValue(19D, "Series 2", "Category 1");
defaultcategorydataset.addValue(29D, "Series 2", "Category 2");
defaultcategorydataset.addValue(41D, "Series 3", "Category 1");
defaultcategorydataset.addValue(33D, "Series 3", "Category 2");
return defaultcategorydataset;
}
private static JFreeChart createChart(CategoryDataset categorydataset)
{
JFreeChart jfreechart = ChartFactory.createBarChart3D("3D Bar Chart Demo", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false);
CategoryPlot categoryplot = jfreechart.getCategoryPlot();
CategoryAxis categoryaxis = categoryplot.getDomainAxis();
categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D));
CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
categoryitemrenderer.setItemLabelsVisible(true);
BarRenderer barrenderer = (BarRenderer)categoryitemrenderer;
barrenderer.setItemMargin(0.20000000000000001D);
return jfreechart;
}
public static JPanel createDemoPanel()
{
JFreeChart jfreechart = createChart(createDataset());
return new ChartPanel(jfreechart);
}
public static void main(String args[])
{
BarChart3DDemo3 barchart3ddemo3 = new BarChart3DDemo3("3D Bar Chart Demo 3");
barchart3ddemo3.pack();
RefineryUtilities.centerFrameOnScreen(barchart3ddemo3);
barchart3ddemo3.setVisible(true);
}
}
试一下这个,调试过的
import java.awt.Dimension;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class BarChart3DDemo3 extends ApplicationFrame
{
public BarChart3DDemo3(String s)
{
super(s);
CategoryDataset categorydataset = createDataset();
JFreeChart jfreechart = createChart(categorydataset);
ChartPanel chartpanel = new ChartPanel(jfreechart);
chartpanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartpanel);
}
private static CategoryDataset createDataset()
{
DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
defaultcategorydataset.addValue(25D, "Series 1", "Category 1");
defaultcategorydataset.addValue(34D, "Series 1", "Category 2");
defaultcategorydataset.addValue(19D, "Series 2", "Category 1");
defaultcategorydataset.addValue(29D, "Series 2", "Category 2");
defaultcategorydataset.addValue(41D, "Series 3", "Category 1");
defaultcategorydataset.addValue(33D, "Series 3", "Category 2");
return defaultcategorydataset;
}
private static JFreeChart createChart(CategoryDataset categorydataset)
{
JFreeChart jfreechart = ChartFactory.createBarChart3D("3D Bar Chart Demo", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false);
CategoryPlot categoryplot = jfreechart.getCategoryPlot();
CategoryAxis categoryaxis = categoryplot.getDomainAxis();
categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D));
CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
categoryitemrenderer.setItemLabelsVisible(true);
BarRenderer barrenderer = (BarRenderer)categoryitemrenderer;
barrenderer.setItemMargin(0.20000000000000001D);
return jfreechart;
}
public static JPanel createDemoPanel()
{
JFreeChart jfreechart = createChart(createDataset());
return new ChartPanel(jfreechart);
}
public static void main(String args[])
{
BarChart3DDemo3 barchart3ddemo3 = new BarChart3DDemo3("3D Bar Chart Demo 3");
barchart3ddemo3.pack();
RefineryUtilities.centerFrameOnScreen(barchart3ddemo3);
barchart3ddemo3.setVisible(true);
}
}
试一下这个,调试过的
#6
有没有画折线图的例子啊.
#7
想要一个曲线的,不过得自己写了~~
#8
我知道可以设最大最小值
但是只显示这两个点没有用过啊