jquery 的一些好插件
By:Roy.LiuLast updated:2014-05-09
import java.awt.Color;
import java.io.File;
import java.io.IOException;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.block.BlockBorder;
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.StandardBarPainter;
import org.jfree.chart.title.LegendTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.ui.RectangleEdge;
import org.jfree.ui.VerticalAlignment;
public class Bar {
public Bar() {
}
private CategoryDataset createDataset() {
double[][] data = new double[][]{
{210, 300, 320,},
{200, 304, 200,},
};
//DatasetUtilities.createCategoryDataset(arg0, arg1, arg2)
UniqueValue a = new UniqueValue("USD", "USD");
UniqueValue b = new UniqueValue("JPY", "JPY");
UniqueValue c = new UniqueValue("FUND", "FUND");
UniqueValue d = new UniqueValue("EQUITY", "EQUITY");
UniqueValue dd = new UniqueValue("SECURITY", "SECURITY");
Comparable[] cats = new UniqueValue[]{a,b};
Comparable[] currencies = new UniqueValue[]{c,d,dd};
return DatasetUtilities.createCategoryDataset(cats, currencies, data);
}
private void createChart(final CategoryDataset dataset) throws IOException {
final JFreeChart chart = ChartFactory.createStackedBarChart(
"", "", "",
dataset, PlotOrientation.VERTICAL, true, false, false);
LegendTitle legend = chart.getLegend();
legend.setPosition(RectangleEdge.RIGHT);
legend.setVerticalAlignment(VerticalAlignment.TOP);
legend.setBackgroundPaint(Color.WHITE);
BlockBorder border = new BlockBorder();
legend.setBorder(BlockBorder.NONE );
chart.setBackgroundPaint(Color.WHITE);
CategoryPlot plot = chart.getCategoryPlot();
((BarRenderer) plot.getRenderer()).setBarPainter(new StandardBarPainter());
//NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
//plot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
plot.setBackgroundPaint(Color.WHITE);
plot.setOutlinePaint(Color.WHITE);
plot.getRenderer().setSeriesPaint(0, new Color(41,77,132));
plot.getRenderer().setSeriesPaint(1, new Color(140,158,198));
int width=640;
int height=480;
File BarChart=new File("d:\\bar.png");
ChartUtilities.saveChartAsPNG(BarChart,chart,width,height);
}
public static void main(final String[] args) throws IOException {
final Bar demo = new Bar();
CategoryDataset ds = demo.createDataset();
demo.createChart(ds);
}
}
================
import java.awt.Color;
import java.awt.Font;
import java.io.File;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PieLabelLinkStyle;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
public class Pie {
@SuppressWarnings("deprecation")
public static void main(String[] args){
try {
DefaultPieDataset dataSet = new DefaultPieDataset();
dataSet.setValue("USD", 10.00);
dataSet.setValue("JPY", 10.00);
dataSet.setValue("HKD", 10.00);
dataSet.setValue("SGD", 10.00);
dataSet.setValue("EUR", 10.00);
dataSet.setValue("AUD", 10.00);
dataSet.setValue("OTHER",40.00);
JFreeChart pieChart=ChartFactory.createPieChart("",dataSet,false,false,false);
/*remove border of pie chart*/
pieChart.setBorderPaint(Color.white);
pieChart.setBorderVisible(false);
System.out.println(pieChart.isBorderVisible());
PiePlot colorConfigurator = (PiePlot) pieChart.getPlot();
colorConfigurator.setCircular(true);
/* change label style */
colorConfigurator.setLabelLinkStyle(PieLabelLinkStyle.STANDARD);
colorConfigurator.setLabelBackgroundPaint(Color.WHITE);
colorConfigurator.setLabelFont(new Font("black", Font.BOLD, 10));
colorConfigurator.setLabelShadowPaint(Color.WHITE);
colorConfigurator.setLabelOutlinePaint(Color.WHITE);
colorConfigurator.setLabelGenerator(new StandardPieSectionLabelGenerator(
"{0} ({2})", NumberFormat.getNumberInstance(),
new DecimalFormat("0.00%")));
/* pie style */
colorConfigurator.setShadowPaint(Color.WHITE);
colorConfigurator.setBackgroundPaint(Color.WHITE);
colorConfigurator.setOutlinePaint(Color.WHITE);
colorConfigurator.setSectionOutlinePaint(Color.WHITE);
colorConfigurator.setSectionPaint("USD", new Color(41,77,132));
colorConfigurator.setSectionPaint("HKD", new Color(140,158,198));
colorConfigurator.setSectionPaint("SGD", new Color(115,170,214));
colorConfigurator.setSectionPaint("EUR", new Color(222,223,231));
colorConfigurator.setSectionPaint("AUD", new Color(189,190,198));
colorConfigurator.setSectionPaint("OTHER", new Color(140,146,156));
colorConfigurator.setSectionPaint("JPY", new Color(0,97,156));
//ColorConfigurator.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}:{1}"));
/* Set color of the label background on the pie chart */
//ColorConfigurator.setLabelBackgroundPaint(new Color(220, 220, 220));
int width=500;
int height=230;
/* PNG file name */
File pieChartFile = new File("d:\\pie.png");
ChartUtilities.saveChartAsPNG(pieChartFile,pieChart,width,height);
}
catch (Exception i)
{
System.out.println(i);
}
}
}
======
public class UniqueValue implements Comparable
private final String uniqueId;
private final String value;
public UniqueValue(String uniqueId, String value) {
this.uniqueId = uniqueId;
this.value = value;
}
@Override
public int compareTo(UniqueValue o) {
return uniqueId.compareTo(o.uniqueId);
}
@Override
public int hashCode() {
return uniqueId.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof UniqueValue) {
return uniqueId.equals(((UniqueValue)obj).uniqueId);
}
return false;
}
@Override
public String toString() {
return value;
}
}
From:一号门
Previous:django model orM 用字典作为参数,保存数据
COMMENTS