📄 chartfactory.html
字号:
<FONT color="green">514</FONT> if (order == null) {<a name="line.514"></a><FONT color="green">515</FONT> throw new IllegalArgumentException("Null 'order' argument.");<a name="line.515"></a><FONT color="green">516</FONT> }<a name="line.516"></a><FONT color="green">517</FONT> MultiplePiePlot plot = new MultiplePiePlot(dataset);<a name="line.517"></a><FONT color="green">518</FONT> plot.setDataExtractOrder(order);<a name="line.518"></a><FONT color="green">519</FONT> plot.setBackgroundPaint(null);<a name="line.519"></a><FONT color="green">520</FONT> plot.setOutlineStroke(null);<a name="line.520"></a><FONT color="green">521</FONT> <a name="line.521"></a><FONT color="green">522</FONT> JFreeChart pieChart = new JFreeChart(new PiePlot3D(null));<a name="line.522"></a><FONT color="green">523</FONT> TextTitle seriesTitle = new TextTitle("Series Title", <a name="line.523"></a><FONT color="green">524</FONT> new Font("SansSerif", Font.BOLD, 12));<a name="line.524"></a><FONT color="green">525</FONT> seriesTitle.setPosition(RectangleEdge.BOTTOM);<a name="line.525"></a><FONT color="green">526</FONT> pieChart.setTitle(seriesTitle);<a name="line.526"></a><FONT color="green">527</FONT> pieChart.removeLegend();<a name="line.527"></a><FONT color="green">528</FONT> pieChart.setBackgroundPaint(null);<a name="line.528"></a><FONT color="green">529</FONT> plot.setPieChart(pieChart);<a name="line.529"></a><FONT color="green">530</FONT> <a name="line.530"></a><FONT color="green">531</FONT> if (tooltips) {<a name="line.531"></a><FONT color="green">532</FONT> PieToolTipGenerator tooltipGenerator <a name="line.532"></a><FONT color="green">533</FONT> = new StandardPieToolTipGenerator();<a name="line.533"></a><FONT color="green">534</FONT> PiePlot pp = (PiePlot) plot.getPieChart().getPlot();<a name="line.534"></a><FONT color="green">535</FONT> pp.setToolTipGenerator(tooltipGenerator);<a name="line.535"></a><FONT color="green">536</FONT> }<a name="line.536"></a><FONT color="green">537</FONT> <a name="line.537"></a><FONT color="green">538</FONT> if (urls) {<a name="line.538"></a><FONT color="green">539</FONT> PieURLGenerator urlGenerator = new StandardPieURLGenerator();<a name="line.539"></a><FONT color="green">540</FONT> PiePlot pp = (PiePlot) plot.getPieChart().getPlot();<a name="line.540"></a><FONT color="green">541</FONT> pp.setURLGenerator(urlGenerator);<a name="line.541"></a><FONT color="green">542</FONT> }<a name="line.542"></a><FONT color="green">543</FONT> <a name="line.543"></a><FONT color="green">544</FONT> JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,<a name="line.544"></a><FONT color="green">545</FONT> plot, legend);<a name="line.545"></a><FONT color="green">546</FONT> <a name="line.546"></a><FONT color="green">547</FONT> return chart;<a name="line.547"></a><FONT color="green">548</FONT> <a name="line.548"></a><FONT color="green">549</FONT> }<a name="line.549"></a><FONT color="green">550</FONT> <a name="line.550"></a><FONT color="green">551</FONT> /**<a name="line.551"></a><FONT color="green">552</FONT> * Creates a bar chart. The chart object returned by this method uses a <a name="line.552"></a><FONT color="green">553</FONT> * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis} <a name="line.553"></a><FONT color="green">554</FONT> * for the domain axis, a {@link NumberAxis} as the range axis, and a <a name="line.554"></a><FONT color="green">555</FONT> * {@link BarRenderer} as the renderer.<a name="line.555"></a><FONT color="green">556</FONT> *<a name="line.556"></a><FONT color="green">557</FONT> * @param title the chart title (<code>null</code> permitted).<a name="line.557"></a><FONT color="green">558</FONT> * @param categoryAxisLabel the label for the category axis <a name="line.558"></a><FONT color="green">559</FONT> * (<code>null</code> permitted).<a name="line.559"></a><FONT color="green">560</FONT> * @param valueAxisLabel the label for the value axis <a name="line.560"></a><FONT color="green">561</FONT> * (<code>null</code> permitted).<a name="line.561"></a><FONT color="green">562</FONT> * @param dataset the dataset for the chart (<code>null</code> permitted).<a name="line.562"></a><FONT color="green">563</FONT> * @param orientation the plot orientation (horizontal or vertical) <a name="line.563"></a><FONT color="green">564</FONT> * (<code>null</code> not permitted).<a name="line.564"></a><FONT color="green">565</FONT> * @param legend a flag specifying whether or not a legend is required.<a name="line.565"></a><FONT color="green">566</FONT> * @param tooltips configure chart to generate tool tips?<a name="line.566"></a><FONT color="green">567</FONT> * @param urls configure chart to generate URLs?<a name="line.567"></a><FONT color="green">568</FONT> *<a name="line.568"></a><FONT color="green">569</FONT> * @return A bar chart.<a name="line.569"></a><FONT color="green">570</FONT> */<a name="line.570"></a><FONT color="green">571</FONT> public static JFreeChart createBarChart(String title,<a name="line.571"></a><FONT color="green">572</FONT> String categoryAxisLabel,<a name="line.572"></a><FONT color="green">573</FONT> String valueAxisLabel,<a name="line.573"></a><FONT color="green">574</FONT> CategoryDataset dataset,<a name="line.574"></a><FONT color="green">575</FONT> PlotOrientation orientation,<a name="line.575"></a><FONT color="green">576</FONT> boolean legend,<a name="line.576"></a><FONT color="green">577</FONT> boolean tooltips,<a name="line.577"></a><FONT color="green">578</FONT> boolean urls) {<a name="line.578"></a><FONT color="green">579</FONT> <a name="line.579"></a><FONT color="green">580</FONT> if (orientation == null) {<a name="line.580"></a><FONT color="green">581</FONT> throw new IllegalArgumentException("Null 'orientation' argument.");<a name="line.581"></a><FONT color="green">582</FONT> }<a name="line.582"></a><FONT color="green">583</FONT> CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);<a name="line.583"></a><FONT color="green">584</FONT> ValueAxis valueAxis = new NumberAxis(valueAxisLabel);<a name="line.584"></a><FONT color="green">585</FONT> <a name="line.585"></a><FONT color="green">586</FONT> BarRenderer renderer = new BarRenderer();<a name="line.586"></a><FONT color="green">587</FONT> if (orientation == PlotOrientation.HORIZONTAL) {<a name="line.587"></a><FONT color="green">588</FONT> ItemLabelPosition position1 = new ItemLabelPosition(<a name="line.588"></a><FONT color="green">589</FONT> ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT);<a name="line.589"></a><FONT color="green">590</FONT> renderer.setPositiveItemLabelPosition(position1);<a name="line.590"></a><FONT color="green">591</FONT> ItemLabelPosition position2 = new ItemLabelPosition(<a name="line.591"></a><FONT color="green">592</FONT> ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT);<a name="line.592"></a><FONT color="green">593</FONT> renderer.setNegativeItemLabelPosition(position2);<a name="line.593"></a><FONT color="green">594</FONT> }<a name="line.594"></a><FONT color="green">595</FONT> else if (orientation == PlotOrientation.VERTICAL) {<a name="line.595"></a><FONT color="green">596</FONT> ItemLabelPosition position1 = new ItemLabelPosition(<a name="line.596"></a><FONT color="green">597</FONT> ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);<a name="line.597"></a><FONT color="green">598</FONT> renderer.setPositiveItemLabelPosition(position1);<a name="line.598"></a><FONT color="green">599</FONT> ItemLabelPosition position2 = new ItemLabelPosition(<a name="line.599"></a><FONT color="green">600</FONT> ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);<a name="line.600"></a><FONT color="green">601</FONT> renderer.setNegativeItemLabelPosition(position2);<a name="line.601"></a><FONT color="green">602</FONT> }<a name="line.602"></a><FONT color="green">603</FONT> if (tooltips) {<a name="line.603"></a><FONT color="green">604</FONT> renderer.setBaseToolTipGenerator(<a name="line.604"></a><FONT color="green">605</FONT> new StandardCategoryToolTipGenerator());<a name="line.605"></a><FONT color="green">606</FONT> }<a name="line.606"></a><FONT color="green">607</FONT> if (urls) {<a name="line.607"></a><FONT color="green">608</FONT> renderer.setBaseItemURLGenerator(<a name="line.608"></a><FONT color="green">609</FONT> new StandardCategoryURLGenerator());<a name="line.609"></a><FONT color="green">610</FONT> }<a name="line.610"></a><FONT color="green">611</FONT> <a name="line.611"></a><FONT color="green">612</FONT> CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, <a name="line.612"></a><FONT color="green">613</FONT> renderer);<a name="line.613"></a><FONT color="green">614</FONT> plot.setOrientation(orientation);<a name="line.614"></a><FONT color="green">615</FONT> JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,<a name="line.615"></a><FONT color="green">616</FONT> plot, legend);<a name="line.616"></a><FONT color="green">617</FONT> <a name="line.617"></a><FONT color="green">618</FONT> return chart;<a name="line.618"></a><FONT color="green">619</FONT> <a name="line.619"></a><FONT color="green">620</FONT> }<a name="line.620"></a><FONT color="green">621</FONT> <a name="line.621"></a><FONT color="green">622</FONT> /**<a name="line.622"></a><FONT color="green">623</FONT> * Creates a stacked bar chart with default settings. The chart object <a name="line.623"></a><FONT color="green">624</FONT> * returned by this method uses a {@link CategoryPlot} instance as the<a name="line.624"></a><FONT color="green">625</FONT> * plot, with a {@link CategoryAxis} for the domain axis, a <a name="line.625"></a><FONT color="green">626</FONT> * {@link NumberAxis} as the range axis, and a {@link StackedBarRenderer} <a name="line.626"></a><FONT color="green">627</FONT> * as the renderer.<a name="line.627"></a><FONT color="green">628</FONT> *<a name="line.628"></a><FONT color="green">629</FONT> * @param title the chart title (<code>null</code> permitted).<a name="line.629"></a><FONT color="green">630</FONT> * @param domainAxisLabel the label for the category axis <a name="line.630"></a><FONT color="green">631</FONT> * (<code>null</code> permitted).<a name="line.631"></a><FONT color="green">632</FONT> * @param rangeAxisLabel the label for the value axis <a name="line.632"></a><FONT color="green">633</FONT> * (<code>null</code> permitted).<a name="line.633"></a><FONT color="green">634</FONT> * @param dataset the dataset for the chart (<code>null</code> permitted).<a name="line.634"></a><FONT color="green">635</FONT> * @param orientation the orientation of the chart (horizontal or <a name="line.635"></a><FONT color="green">636</FONT> * vertical) (<code>null</code> not permitted).<a name="line.636"></a><FONT color="green">637</FONT> * @param legend a flag specifying whether or not a legend is required.<a name="line.637"></a><FON
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -