Class SimpleBarChart
A small chart of horizontal bars that compares a few values: a name at the left of each bar, the value at its end, and no axis, grid or legend, on a light panel, with a title and a subtitle at the top. One bar can be highlighted, in navy, its name and value bold, as the best of the values: the bar of an index, or the lowest or the highest value, which the chart finds. Each bar is as long as its share of the largest value. A dashed line can mark a value across the bars, a target or an average, and the bars can have rounded ends.
It is meant to stand beside a Table of the same numbers: the chart for the picture, the table for the record and for a screen reader. In a PDF/UA document the chart is one figure, described from its title and its values unless an alternate description is set. For grouped, stacked or vertical bars with an axis, use BarChart. Please see Example_20.
public class SimpleBarChart : IDrawable
- Inheritance
-
SimpleBarChart
- Implements
- Inherited Members
Constructors
SimpleBarChart(Font, Font)
Creates a simple bar chart, 300 points wide.
public SimpleBarChart(Font f1, Font f2)
Parameters
f1Fontthe font of the title and of the highlighted bar's name and value, a bold one.
f2Fontthe font of the subtitle and of the other names and values.
Methods
Add(string, float)
Adds a bar: its name and its value. A value below zero is drawn as no bar, with its value written. A value that is NaN or infinite has no bar and no value, as in the other charts, and the description leaves it out.
public SimpleBarChart Add(string name, float value)
Parameters
Returns
- SimpleBarChart
this chart.
DrawOn(Page)
Draws the chart on the page.
public float[] DrawOn(Page page)
Parameters
pagePagethe page to draw on.
Returns
- float[]
the x and y coordinates of the bottom right corner of the chart.
GetHeight()
Returns the height of the chart: its padding, its title and subtitle, and a row for each bar.
public float GetHeight()
Returns
- float
the height of the chart.
SetAltDescription(string)
Sets the alternate description of the chart in a PDF/UA document. Without one the chart is described from its title, its subtitle and its values.
public SimpleBarChart SetAltDescription(string altDescription)
Parameters
altDescriptionstringthe alternate description.
Returns
- SimpleBarChart
this chart.
SetBarColor(int)
Sets the color of the bars that are not highlighted. It is gray, 0xA7AFB8, unless set.
public SimpleBarChart SetBarColor(int color)
Parameters
colorintthe color.
Returns
- SimpleBarChart
this chart.
SetFractionDigits(int)
Sets the number of digits after the decimal point of the values, all of them alike. Without it a value has as many as it needs, two at most.
public SimpleBarChart SetFractionDigits(int digits)
Parameters
digitsintthe number of digits.
Returns
- SimpleBarChart
this chart.
SetHighlight(int)
Highlights the bar of the index, the first bar 0: it is drawn in the highlight color, its name and value in the bold font. Which bar is the best, the lowest value or the highest, is the caller's to say.
public SimpleBarChart SetHighlight(int index)
Parameters
indexintthe index of the bar.
Returns
- SimpleBarChart
this chart.
SetHighlightColor(int)
Sets the color of the highlighted bar and of its name. It is navy, 0x1F3A5F, unless set.
public SimpleBarChart SetHighlightColor(int color)
Parameters
colorintthe color.
Returns
- SimpleBarChart
this chart.
SetHighlightHighest()
Highlights the bar of the highest value, the best of sales or scores; the first of them when two are highest. Bars added later count too, as the chart finds the bar when it is drawn.
public SimpleBarChart SetHighlightHighest()
Returns
- SimpleBarChart
this chart.
SetHighlightLowest()
Highlights the bar of the lowest value, the best of times or prices; the first of them when two are lowest. Bars added later count too, as the chart finds the bar when it is drawn.
public SimpleBarChart SetHighlightLowest()
Returns
- SimpleBarChart
this chart.
SetLocation(float, float)
Sets the top left corner of the chart.
public SimpleBarChart SetLocation(float x, float y)
Parameters
Returns
- SimpleBarChart
this chart.
SetPanelColor(int)
Sets the color of the panel behind the chart. It is light gray, 0xF1F3F6, unless set. Color.transparent, -1, draws no panel: the one color setter where it does not leave the color as it was.
public SimpleBarChart SetPanelColor(int color)
Parameters
colorintthe color.
Returns
- SimpleBarChart
this chart.
SetReferenceLine(float, string)
Draws a thin dashed line across the bars at a value, a target or an average, with its label and value under the bars: "Target 50". The bars are scaled so that the line fits, should it be past the largest value. A value that is negative, NaN or infinite draws no line.
public SimpleBarChart SetReferenceLine(float value, string label)
Parameters
Returns
- SimpleBarChart
this chart.
SetRoundedBars(bool)
Draws the bars with slightly rounded ends. They are square unless set.
public SimpleBarChart SetRoundedBars(bool roundedBars)
Parameters
roundedBarsbooltrue for rounded ends.
Returns
- SimpleBarChart
this chart.
SetSubtitle(string)
Sets the subtitle, drawn small and gray under the title: the unit of the values, say.
public SimpleBarChart SetSubtitle(string subtitle)
Parameters
subtitlestringthe subtitle.
Returns
- SimpleBarChart
this chart.
SetTitle(string)
Sets the title, drawn at the top left of the chart.
public SimpleBarChart SetTitle(string title)
Parameters
titlestringthe title.
Returns
- SimpleBarChart
this chart.
SetWidth(float)
Sets the width of the chart. Its height follows from the fonts and the number of bars; see GetHeight.
public SimpleBarChart SetWidth(float w)
Parameters
wfloatthe width.
Returns
- SimpleBarChart
this chart.