求大神指教 JFree chart 这个图表怎么做
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了求大神指教 JFree chart 这个图表怎么做相关的知识,希望对你有一定的参考价值。
对啊,这个不难的,网上搜JFreeChart 3D饼图,很多例子代码的,封装一下,然后传递参数就行了。下面是我整理的代码:
package ping.chart;
import java.awt.Font;
import java.io.FileOutputStream;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;
/**
* JFreeChart出生Swing形式的饼图
*
* @author LiuYanPing
*
*/
@SuppressWarnings("serial")
public class PPieChart3D extends JPanel
public String chart_title="TEST";
private JFreeChart chart;
/**
* @author LiuYanPING
* @param title
* @param xtitle
* @param ytitle
* @param data must be String[][2];String[][1] must be integer
* @return
*/
public JPanel createPanel(String title,String [][]data)
chart_title=title;
chart = createJFreeChart(createDataSet(data));
return new ChartPanel(chart);
/**
* @author LiuYanPING
* @param CHART_PATH like "./xx/"
* @param charName like "xxx.jpg"
* @return
*/
public String SaveAsPNG(String CHART_PATH,String charName)
FileOutputStream fos_jpg = null;
try
if(null==CHART_PATH) return null;
String chartName = CHART_PATH + charName;
fos_jpg = new FileOutputStream(chartName);
ChartUtilities.writeChartAsPNG(fos_jpg, chart, 500, 500, true, 10);
return chartName;
catch (Exception e)
e.printStackTrace();
return null;
finally
try
fos_jpg.close();
catch (Exception e)
e.printStackTrace();
private DefaultPieDataset createDataSet(String [][]data)
DefaultPieDataset dataset = new DefaultPieDataset();
for(int i=0;i<data.length;i++)
dataset.setValue(data[i][0],Integer.parseInt(data[i][1]));
return dataset;
private JFreeChart createJFreeChart(DefaultPieDataset dataset)
/**
* 构建JFreeChart
*/
// JFreeChart jfreeChart
JFreeChart jfreeChart = ChartFactory.createPieChart3D(chart_title, dataset, true, false, false);
/**
* 设置JFreeChart的属性
*/
jfreeChart.setTitle(new TextTitle(chart_title, new Font("宋体", Font.BOLD
+ Font.ITALIC, 20)));
return jfreeChart;
你直接调用
createPanel(String title,String [][]data)
就行了 参考技术A 3D饼图啊
看给的例子里都有的 有个demo文件夹,里面全是例子追问
demo有,没代码的
maven下载的时候出现的问题,求大神指教
[WARNING] An error occurred during dependency resolution.
Failed to retrieve org.apache.struts:struts2-core-2.3.14.2
Caused by: Unable to download the artifact from any repository
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=org.apache.struts -DartifactId=struts2-co
re -Dversion=2.3.14.2 -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=org.apache.struts -DartifactId=struts2-core
-Dversion=2.3.14.2 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -Drepositor
yId=[id]
Path to dependency:
1) com.ailk.aiwmWap:aiwmWap:war:1.0-SNAPSHOT
2) org.apache.struts:struts2-core:jar:2.3.14.2
org.apache.struts:struts2-core:jar:2.3.14.2
from the specified remote repositories:
maven (http://repo1.maven.org/maven2),
codehaus (http://repository.codehaus.org/),
AsiainfoCUVSD (http://vsd.asiainfo.com/maven),
ibiblio (http://mirrors.ibiblio.org/pub/mirrors/maven2),
central (http://repo1.maven.org/maven2)
[INFO] Unable to read jar manifest from C:\Documents and Settings\Administrator\
.m2\repository\org\apache\struts\struts2-core\2.3.14.2\struts2-core-2.3.14.2.jar
[INFO] Using source status cache: D:\MyEclipse 8.5\cooding\aiwmWap2\target\mvn-e
clipse-cache.properties
尝试以下方式:
确保网络连接问题,与IE一致:在$Maven_Home/conf/settings.xml 设置。
确保pom.xml文件依赖正确:
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.2.1</version>
<scope>compile</scope>
</dependency>
3. 删除文件夹,重新下载 C:\\***\\.2\\repository\\org\\apache\\.struts
4. 更改下载库
以上是关于求大神指教 JFree chart 这个图表怎么做的主要内容,如果未能解决你的问题,请参考以下文章
我用JQuery miniui 做了一个表格,求大神指教一个下拉框问题