public class BarChart extends AbstractChart
AbstractChart.Side
axisColour, axisFormatter, axisLabelColour, axisValuesColour, data, drawDecorations, graphics, logTics, parent, renderer, showEdge, tics, transposeAxes
Constructor and Description |
---|
BarChart(processing.core.PApplet parent)
Initialises a bar chart.
|
Modifier and Type | Method and Description |
---|---|
void |
draw(float xOrigin,
float yOrigin,
float width,
float height)
Draws the bar chart within the given bounds.
|
float[] |
getData()
Reports the data values used to calculate bar lengths in the chart.
|
processing.core.PVector |
getDataToScreen(processing.core.PVector dataPoint)
Converts given data point into its screen location.
|
float |
getMaxValue()
Reports the maximum value that can be displayed by the bar chart.
|
float |
getMinValue()
Reports the minimum value that can be displayed by the bar chart.
|
int |
getNumBars()
Reports the number of bars in the bar chart.
|
processing.core.PVector |
getScreenToData(processing.core.PVector screenPoint)
Converts given screen coordinate into its equivalent data value.
|
void |
setBarColour(float[] colourData,
ColourTable cTable)
Provides the data and colour table from which to colour bars.
|
void |
setBarColour(int colour)
Determines the colours of the bars to be displayed on the chart.
|
void |
setBarGap(float gap)
Sets the gap between adjacent bars.
|
void |
setBarLabels(java.lang.String[] labels)
Sets the bar names to be displayed as axis labels.
|
void |
setBarPadding(float padding)
Sets the padding between adjacent bars.
|
void |
setCategoryAxisAt(float value)
Sets the position of the category axis.
|
void |
setCategoryAxisLabel(java.lang.String label)
Sets the category axis label.
|
void |
setCategoryFormat(java.lang.String format)
Sets the numerical format for numbers shown on the category axis.
|
void |
setData(float[] values)
Sets the data values to be displayed in the chart.
|
void |
setLogValues(boolean isLog)
Determines whether or not the values represented by the length of each bar should be log10-scaled.
|
void |
setMaxValue(float maxVal)
Sets the maximum value for the bar chart.
|
void |
setMinValue(float minVal)
Sets the minimum value for the bar chart.
|
void |
setReverseCategories(boolean reverse)
Determines if the order of the category values should be reversed or not.
|
void |
setValueAxisLabel(java.lang.String label)
Sets the value axis label.
|
void |
setValueFormat(java.lang.String format)
Sets the numerical format for numbers shown on the value axis.
|
void |
showCategoryAxis(boolean showAxis)
Determines whether or not the category axis is drawn.
|
void |
showValueAxis(boolean showAxis)
Determines whether or not the value axis is drawn.
|
void |
transposeAxes(boolean transpose)
Determines if the axes should be transposed (so that categories appear on the
vertical axis and values on the horizontal axis).
|
void |
updateLayout()
Updates the layout of the chart if, for example the font has been changed externally.
|
convertFromLog, convertToLog, getBorder, getData, getIsLogScale, getMax, getMaxLog, getMin, getMinBorder, getMinLog, getShowAxis, setAxisColour, setAxisLabelColour, setAxisValuesColour, setBorder, setData, setDecorations, setFormat, setGraphics, setIsLogScale, setMax, setMin, setMinBorder, setMinBorder, setRange, setRenderer, setShowEdge, showAxis
public BarChart(processing.core.PApplet parent)
parent
- Parent sketch in which this chart is to be drawn.public void setData(float[] values)
values
- Sequence of values to chart.public float[] getData()
public void draw(float xOrigin, float yOrigin, float width, float height)
draw
in class AbstractChart
xOrigin
- left-hand pixel coordinate of the area in which to draw the chart.yOrigin
- top pixel coordinate of the area in which to draw the chart.width
- Width in pixels of the area in which to draw the chart.height
- Height in pixels of the area in which to draw the chart.public processing.core.PVector getDataToScreen(processing.core.PVector dataPoint)
draw()
method. If this is called before any call to draw()
has
been made, it will return null.dataPoint
- (x,y) pair representing an item of data.public processing.core.PVector getScreenToData(processing.core.PVector screenPoint)
draw()
method.
If this is called before any call to draw()
has been made, it will return null.
The x-value of the returned data point corresponds to the zero-indexed counter of the number
of bars (i.e if the screen location falls within the first bar, the x-value will be 0, if
it falls within the second 1 will be returned etc.).screenPoint
- Screen coordinates to convert into data pair.public int getNumBars()
public void setLogValues(boolean isLog)
isLog
- True if values are to be log10-scaled or false if linear.public void setMinValue(float minVal)
Float.NaN
, then
the minimum value will be set to the minimum of the data values in the chart.minVal
- Minimum value to use for scaling bar lengths or Float.NaN
if data minimum is to be used.public float getMinValue()
setMinValue()
can affect the value.public float getMaxValue()
setMaxValue()
can affect the value.public void setMaxValue(float maxVal)
Float.NaN
, then
the maximum value will be set to the maximum of the data values in the chart.maxVal
- Maximum value to use for scaling bar lengths or Float.NaN
if data maximum is to be used.public void setCategoryAxisAt(float value)
value
- Position of axis in data units.public void setBarLabels(java.lang.String[] labels)
labels
- Array of labels corresponding to each of the bars in the chart.public void showValueAxis(boolean showAxis)
showAxis
- Value axis is drawn if true.public void showCategoryAxis(boolean showAxis)
showAxis
- Category axis is drawn if true.public void transposeAxes(boolean transpose)
transpose
- Axes are transposed if true.public void updateLayout()
public void setBarGap(float gap)
gap
- Gap between adjacent bars in pixel units.public void setBarPadding(float padding)
padding
- Padding around bars in pixel units.public void setReverseCategories(boolean reverse)
reverse
- Category order reversed if true.public void setValueFormat(java.lang.String format)
format
- Format for numbers on the value axis.public void setCategoryFormat(java.lang.String format)
format
- Format for numbers on the category axis.public void setCategoryAxisLabel(java.lang.String label)
label
- Category axis label to draw or null if no label to be drawn.public void setValueAxisLabel(java.lang.String label)
label
- Value-axis label to draw or null if no label to be drawn.public void setBarColour(int colour)
colour
- Colour of bars.public void setBarColour(float[] colourData, ColourTable cTable)
setData()
.colourData
- Data used to colour barscTable
- Colour table that translates data values into colours.