Class BarChart
Bar chart renderer for PDF pages: one slot per category, the bars of the series grouped inside each slot. A value of a line series outside a range that is set cuts its line at the edge of the plot, and the chart says how many are: "2 values outside the range", small, under the plot at its right end, and in its description, in that alone when the plot would not be left room to draw. See Example_27, of horizontal and vertical bars.
public class BarChart : IDrawable
- Inheritance
-
BarChart
- Implements
- Inherited Members
Constructors
BarChart(Font, Font)
Creates a bar chart.
public BarChart(Font f1, Font f2)
Parameters
f1Fontthe font for the chart title.
f2Fontthe font for the axis titles, the labels and the legend.
Methods
AddLineSeries(string, float[])
Adds a series drawn as a line over the bars, in ink, a dot at each category: a target, the average, or last year. It shares the value axis with the bars, is not stacked, and is in the legend and the description. A value that is NaN or infinite leaves a gap in the line, and the chart says how many values are outside a range set with SetValueAxisRange.
public BarChart AddLineSeries(string name, float[] values)
Parameters
namestringthe series name, shown in the legend; empty for none.
valuesfloat[]one value per category.
Returns
- BarChart
this BarChart object.
AddLineSeries(string, float[], int)
Adds a series drawn as a line over the bars, in the specified color.
public BarChart AddLineSeries(string name, float[] values, int color)
Parameters
namestringthe series name, shown in the legend; empty for none.
valuesfloat[]one value per category.
colorintthe line color as a 0xRRGGBB value.
Returns
- BarChart
this BarChart object.
AddSeries(string, float[])
Adds a series drawn in the next color of the default palette. A value that is NaN or infinite has no bar.
public BarChart AddSeries(string name, float[] values)
Parameters
namestringthe series name, shown in the legend; empty for none.
valuesfloat[]one value per category.
Returns
- BarChart
this BarChart object.
AddSeries(string, float[], int)
Adds a series drawn in the specified color.
public BarChart AddSeries(string name, float[] values, int color)
Parameters
namestringthe series name, shown in the legend; empty for none.
valuesfloat[]one value per category.
colorintthe bar color as a 0xRRGGBB value, for example Color.blue.
Returns
- BarChart
this BarChart object.
AddSeries(string, float[], int[])
Adds a series with a color per category, for a chart whose bars each have their own color. A bar past the end of the colors has the next color of the default palette.
public BarChart AddSeries(string name, float[] values, int[] colors)
Parameters
namestringthe series name, shown in the legend; empty for none.
valuesfloat[]one value per category.
colorsint[]one 0xRRGGBB color per category.
Returns
- BarChart
this BarChart object.
DrawOn(Page)
Draws this chart on the specified page. A category name wider than two fifths of a horizontal chart is shortened with an ellipsis, and a chart too small for its plot draws nothing.
public float[] DrawOn(Page page)
Parameters
pagePagethe page to draw on.
Returns
- float[]
the bottom right corner coordinates [x, y].
SetAltDescription(string)
Sets the alternate description of the chart, which a screen reader reads in a PDF/UA document, where the chart is a figure. The default is the title and the subtitle, or "Bar chart" without them, and the values of each series by category. Describe what the chart shows. The number of values of the line series outside a range that is set follows it, as the chart prints it.
public BarChart SetAltDescription(string altDescription)
Parameters
altDescriptionstringthe alternate description.
Returns
- BarChart
this BarChart object.
SetBarGap(float)
Sets the gap between the bars of a group as a fraction of the bar width. The default is 0.0, so the bars of a group touch.
public BarChart SetBarGap(float gap)
Parameters
gapfloatthe gap.
Returns
- BarChart
this BarChart object.
SetCategories(params string[])
Sets the categories, one per group of bars, in the order they are drawn: left to right in a vertical chart, top to bottom in a horizontal one.
public BarChart SetCategories(params string[] categories)
Parameters
categoriesstring[]the category labels.
Returns
- BarChart
this BarChart object.
SetFractionDigits(int)
Sets the number of digits after the decimal point of the values written by the bars, all of them alike, as SimpleBarChart's. Without it a value has as many as it needs, two at most, or as many as the step of the value axis has. The numbers of the value axis have the digits of its step.
public BarChart SetFractionDigits(int digits)
Parameters
digitsintthe number of digits.
Returns
- BarChart
this BarChart object.
SetGridLineColor(int)
Sets the color of the grid lines. The default is light gray, 0xE1E4E8. Color.transparent leaves it unchanged.
public BarChart SetGridLineColor(int color)
Parameters
colorintthe color as a 0xRRGGBB value, for example Color.lightgray.
Returns
- BarChart
this BarChart object.
SetGridLines(bool)
Sets whether the grid lines of the value axis are drawn.
public BarChart SetGridLines(bool drawGridLines)
Parameters
drawGridLinesbooltrue to draw them.
Returns
- BarChart
this BarChart object.
SetGroupGap(float)
Sets the gap between the groups of bars as a fraction of the category slot, from 0.0 to 0.9. The default is 0.3.
public BarChart SetGroupGap(float gap)
Parameters
gapfloatthe gap.
Returns
- BarChart
this BarChart object.
SetGroupingUsed(bool)
Sets whether the labels group the digits in thousands with a comma, as in 6,650. The default is true.
public BarChart SetGroupingUsed(bool groupingUsed)
Parameters
groupingUsedbooltrue to group the digits.
Returns
- BarChart
this BarChart object.
SetHorizontal(bool)
Sets whether the bars are horizontal. The default is vertical bars.
public BarChart SetHorizontal(bool horizontal)
Parameters
horizontalbooltrue for horizontal bars.
Returns
- BarChart
this BarChart object.
SetLegend(bool)
Sets whether the legend is drawn. The legend lists the series that have a name, under the title.
public BarChart SetLegend(bool drawLegend)
Parameters
drawLegendbooltrue to draw the legend.
Returns
- BarChart
this BarChart object.
SetLocation(float, float)
Sets the location of the top left corner of this chart.
public BarChart SetLocation(float x, float y)
Parameters
Returns
- BarChart
this BarChart object.
SetSize(float, float)
Sets the size of this chart.
public BarChart SetSize(float w, float h)
Parameters
Returns
- BarChart
this BarChart object.
SetStacked(bool)
Sets whether the series are stacked: one bar per category, with the value of each series as a segment of it. The values above 0 stack up from 0 and the values below 0 stack down. The default is grouped bars.
public BarChart SetStacked(bool stacked)
Parameters
stackedbooltrue for stacked bars.
Returns
- BarChart
this BarChart object.
SetSubtitle(string)
Sets the subtitle, written in gray under the title in the second font.
public BarChart SetSubtitle(string subtitle)
Parameters
subtitlestringthe subtitle.
Returns
- BarChart
this BarChart object.
SetTitle(string)
Sets the chart title.
public BarChart SetTitle(string title)
Parameters
titlestringthe title.
Returns
- BarChart
this BarChart object.
SetValueAxisRange(float, float)
Sets the range of the value axis, with grid lines on a round step, as SetYAxisRange does in SimpleLineChart and SimpleScatterChart. Without it the range is that of the data, rounded to steps, and always includes 0. A range whose end is not past its start is not set. A value of a line series outside the range is drawn past the plot, which clips it, and the chart says how many are, under the plot, which is that much shorter, and in its description.
public BarChart SetValueAxisRange(float min, float max)
Parameters
Returns
- BarChart
this BarChart object.
SetValueLabels(bool)
Sets whether the value of each bar is written at its end, or, in a stacked chart, inside each segment that has room for it.
public BarChart SetValueLabels(bool drawValueLabels)
Parameters
drawValueLabelsbooltrue to write the values.
Returns
- BarChart
this BarChart object.
SetValueLabelsInside(bool)
Sets whether the value labels are written inside the bars, at the end of each bar, in white or in ink, whichever reads on the bar's color, instead of next to the bar ends. A bar too short for its label gets it next to its end. The default is false.
public BarChart SetValueLabelsInside(bool valueLabelsInside)
Parameters
valueLabelsInsidebooltrue to write the values inside the bars.
Returns
- BarChart
this BarChart object.
SetXAxisTitle(string)
Sets the X axis title.
public BarChart SetXAxisTitle(string title)
Parameters
titlestringthe title.
Returns
- BarChart
this BarChart object.
SetYAxisTitle(string)
Sets the Y axis title.
public BarChart SetYAxisTitle(string title)
Parameters
titlestringthe title.
Returns
- BarChart
this BarChart object.