📄 axischart.java
字号:
//---Determine how many labels will fit on the x-axis
this.xAxis.computeScalePixelWidthDataAxis();
this.yAxis.computeScalePixelWidth();
this.xAxis.computeOneUnitPixelSize( this.xAxis.getScalePixelWidth(), this.xAxis.getScaleCalculator().getIncrement() );
//---we ADD to the origin position when doing x-axis
float zeroLineCoordinate = ( float ) ( this.xAxis.getOrigin() + ( this.xAxis.getScalePixelWidth() * ( -this.xAxis.getScaleCalculator().getMinValue() ) ) / this.xAxis.getScaleCalculator().getIncrement() );
this.xAxis.setZeroLineCoordinate( zeroLineCoordinate );
}
else
{
//DataAxisProperties dataAxisProperties = ( DataAxisProperties ) this.axisProperties.getYAxisProperties();
this.xAxis.computeScalePixelWidth();
this.yAxis.computeScalePixelWidthDataAxis();
this.yAxis.computeOneUnitPixelSize( this.yAxis.getScalePixelWidth(), this.yAxis.getScaleCalculator().getIncrement() );
//---we SUBTRACT to the origin position when doing y-axis
float zeroLineCoordinate = ( float ) ( this.yAxis.getOrigin() - ( this.yAxis.getScalePixelWidth() * ( -this.yAxis.getScaleCalculator().getMinValue() ) ) / this.yAxis.getScaleCalculator().getIncrement() );
this.yAxis.setZeroLineCoordinate( zeroLineCoordinate );
}
this.xAxis.computeTickStart();
}
/********************************************************************************************
* Implement the method to render the Axis based chart
*
* @throws ChartDataException
* @throws PropertyException there are several validations done to aid in development of the
* charts.
********************************************************************************************/
protected void renderChart() throws ChartDataException, PropertyException
{
if( super.getChartProperties().validate() )
{
this.iAxisDataSeries.validate();
}
//---this is not an optional validation
this.validateHorizontalPlot();
Graphics2D g2d = super.getGraphics2D();
g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
FontRenderContext fontRenderContext = g2d.getFontRenderContext();
//---cache calcs used more than once
float edgePaddingTimesTwo = super.getChartProperties().getEdgePadding() * 2;
//---start off with total image width and we will subtract components from that.
float xAxisWidth = super.getImageWidth() - edgePaddingTimesTwo;
float yAxisHeight = super.getImageHeight() - edgePaddingTimesTwo;
//---render the TITLE. If no title, this will return zero.
float chartTitleHeight = super.renderChartTitle( this.getIAxisDataSeries().getChartTitle(), fontRenderContext );
yAxisHeight -= chartTitleHeight;
//---if there is a legend...
if( super.getLegend() != null )
{
//---PROCESS the size needed for drawing the legend.
super.getLegend().computeLegendXY( this.iAxisDataSeries, chartTitleHeight );
if( ( super.getLegend().getLegendProperties().getPlacement() == LegendAreaProperties.RIGHT )
|| ( super.getLegend().getLegendProperties().getPlacement() == LegendAreaProperties.LEFT ) )
{
xAxisWidth -= super.getLegend().getLegendProperties().getChartPadding();
xAxisWidth -= super.getLegend().getWidth();
}
else //LegendAreaProperties.BOTTOM, OR LegendAreaProperties.TOP
{
yAxisHeight -= this.getLegend().getLegendProperties().getChartPadding();
yAxisHeight -= this.getLegend().getHeight();
}
super.getLegend().render();
}
AxisChartDataProcessor axisChartDataProcessor = this.createAxisChartDataProcessor();
axisChartDataProcessor.processData( this, fontRenderContext );
this.setupAxis( axisChartDataProcessor, fontRenderContext );
this.sizeAndPositionAxis( xAxisWidth, yAxisHeight, chartTitleHeight );
this.deriveAxisValues();
//---PAINT THE BACKGROUND OF AXIS
if( this.getAxisProperties().getBackgroundPaint() != null )
{
Rectangle2D.Float rectangle = new Rectangle2D.Float( this.xAxis.getOrigin() + 1,
this.yAxis.getOrigin() - this.yAxis.getPixelLength(),
this.xAxis.getPixelLength(),
this.yAxis.getPixelLength() );
g2d.setPaint( this.axisProperties.getBackgroundPaint() );
g2d.fill( rectangle );
}
this.yAxis.render( g2d, this.getAxisProperties(), iAxisDataSeries.getYAxisTitle() );
this.xAxis.render( g2d, this.getAxisProperties(), iAxisDataSeries.getXAxisTitle() );
//---SCALE CLIPPING REGION
//---if the user defined the scale, chart may be off the 'screen' so set a clipping region so only draw in the chart.
Rectangle2D.Float rectangle = new Rectangle2D.Float( this.getXAxis().getOrigin(),
this.getYAxis().getOrigin() - this.getYAxis().getPixelLength() + 1,
this.xAxis.getPixelLength() + 1,
this.yAxis.getPixelLength() - 2 );
g2d.setClip( rectangle );
//---IMAGE MAP setup
//---if we are saving all the coordinates for an ImageMap, create the ImageMap Object as we
//--- know how many area elements there are.
if( super.getGenerateImageMapFlag() )
{
//---pass the size to try and avoid having the expense of resizing the ArrayList
ImageMap imageMap = new ImageMap( iAxisDataSeries.size() * iAxisDataSeries.getTotalNumberOfDataSets() );
super.setImageMap( imageMap );
}
//---draw the charts over the axis...
overlayCharts();
}
/********************************************************************************************
* Draws the charts over the axis. We have to render in a specific order so combo charts
* get drawn correctly
*
* @throws PropertyException
******************************************************************************************/
protected void overlayCharts() throws PropertyException, ChartDataException
{
IAxisPlotDataSet iAxisPlotDataSet;
iAxisPlotDataSet = this.iAxisDataSeries.getIAxisPlotDataSet( ChartType.AREA_STACKED );
if( iAxisPlotDataSet != null )
{
StackedAreaChart.render( this, ( IAxisChartDataSet ) iAxisPlotDataSet );
}
iAxisPlotDataSet = this.iAxisDataSeries.getIAxisPlotDataSet( ChartType.AREA );
if( iAxisPlotDataSet != null )
{
AreaChart.render( this, ( IAxisChartDataSet ) iAxisPlotDataSet );
}
iAxisPlotDataSet = this.iAxisDataSeries.getIAxisPlotDataSet( ChartType.BAR );
if( iAxisPlotDataSet != null )
{
BarChart.render( this, ( IAxisChartDataSet ) iAxisPlotDataSet );
}
iAxisPlotDataSet = this.iAxisDataSeries.getIAxisPlotDataSet( ChartType.BAR_STACKED );
if( iAxisPlotDataSet != null )
{
StackedBarChart.render( this, ( IAxisChartDataSet ) iAxisPlotDataSet );
}
iAxisPlotDataSet = this.iAxisDataSeries.getIAxisPlotDataSet( ChartType.BAR_CLUSTERED );
if( iAxisPlotDataSet != null )
{
ClusteredBarChart.render( this, ( IAxisChartDataSet ) iAxisPlotDataSet );
}
iAxisPlotDataSet = this.iAxisDataSeries.getIAxisPlotDataSet( ChartType.STOCK );
if( iAxisPlotDataSet != null )
{
StockChart.render( this, ( IStockChartDataSet ) iAxisPlotDataSet );
}
iAxisPlotDataSet = this.iAxisDataSeries.getIAxisPlotDataSet( ChartType.LINE );
if( iAxisPlotDataSet != null )
{
LineChart.render( this, ( IAxisChartDataSet ) iAxisPlotDataSet );
}
iAxisPlotDataSet = this.iAxisDataSeries.getIAxisPlotDataSet( ChartType.POINT );
if( iAxisPlotDataSet != null )
{
PointChart.render( this, ( IAxisChartDataSet ) iAxisPlotDataSet );
}
}
/**********************************************************************************************
* Currently, we only support the bar chart types being horizontal, and you can not have a
* horizontally plotted bar chart in a combo chart.
*
* @throws PropertyException
**********************************************************************************************/
private void validateHorizontalPlot() throws PropertyException
{
if( axisProperties.isPlotHorizontal() )
{
//---if there is only one data set, there is no need to do any validations.
if( this.iAxisDataSeries.size() > 1 )
{
throw new PropertyException( "You can not have a combo chart on a horizontal plot." );
}
if( !this.allowHorizontalPlot() )
{
throw new PropertyException( "Horizontal plots are only supported in the Bar, Stacked Bar, and Clustered Bar Chart Types." );
}
}
}
/******************************************************************************************
* We only allow horizontal plots for the Bar Chart types in this release.
*
* @return boolean
******************************************************************************************/
private boolean allowHorizontalPlot()
{
if( this.iAxisDataSeries.getIAxisPlotDataSet( ChartType.BAR ) != null )
{
return true;
}
if( this.iAxisDataSeries.getIAxisPlotDataSet( ChartType.BAR_STACKED ) != null )
{
return true;
}
if( this.iAxisDataSeries.getIAxisPlotDataSet( ChartType.BAR_CLUSTERED ) != null )
{
return true;
}
return false;
}
/**************************************************************************************************
*
***************************************************************************************************/
public AxisProperties getAxisProperties()
{
return this.axisProperties;
}
/**************************************************************************************************
*
***************************************************************************************************/
public XAxis getXAxis()
{
return this.xAxis;
}
/**************************************************************************************************
*
***************************************************************************************************/
public YAxis getYAxis()
{
return this.yAxis;
}
/**********************************************************************************************
* Enables the testing routines to display the contents of this Object. Override Chart
* implementation as PieCharts use AreaProperties directly rather than a child.
*
* @param htmlGenerator
* @param imageFileName
* @param imageMap if this is NULL we are not creating image map data in html
**********************************************************************************************/
public void toHTML( HTMLGenerator htmlGenerator, String imageFileName, ImageMap imageMap )
{
htmlGenerator.chartTableStart( this.getClass().getName(), imageFileName, imageMap );
if( this.iAxisDataSeries instanceof HTMLTestable )
{
( ( HTMLTestable ) this.iAxisDataSeries ).toHTML( htmlGenerator );
}
//---AxisProperties
htmlGenerator.chartTableRowStart();
this.axisProperties.toHTML( htmlGenerator );
htmlGenerator.chartTableRowEnd();
//---XAxis
htmlGenerator.chartTableRowStart();
this.xAxis.toHTML( htmlGenerator );
htmlGenerator.chartTableRowEnd();
//---YAxis
htmlGenerator.chartTableRowStart();
this.yAxis.toHTML( htmlGenerator );
htmlGenerator.chartTableRowEnd();
//---ChartProperties
htmlGenerator.chartTableRowStart();
super.getChartProperties().toHTML( htmlGenerator );
htmlGenerator.chartTableRowEnd();
if( super.getLegend() != null )
{
htmlGenerator.chartTableRowStart();
this.getLegend().toHTML( htmlGenerator );
htmlGenerator.chartTableRowEnd();
}
htmlGenerator.chartTableEnd();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -