-
Notifications
You must be signed in to change notification settings - Fork 0
3.4.1 BarDiagram
Kristiantvaa edited this page Jul 3, 2024
·
10 revisions
Required:
-
data: number[]
The data to plot. -
labels: string[]
The labels corresponding to each bar. -
xAxisTitle: string
Title of the x-axis. -
yAxisTitle: string
Title of the y-axis.
Optional:
-
basePosition?: [number, number]
Where to position the diagram in the Graphica-window. -
diagramTitle?: string
Title of the bar diagram. -
xAxisUnit?: string
The unit for the x-axis. -
yAxisUnit?: string
The unit for the y-axis.
-
createBarDiagram()
Calls all the add-functions to create the diagram.-
addBars() : number
Adds all the bars (Polygons) with Text for the corresponding data-values and labels-values. Returns the end-position of the bars horizontally. -
addAxes(xAxisEnd: number)
Adds two Lines as axes and adds a axis-title.xAxisEnd
is used for calculating the length of the x-axis. -
addTitle(position: [number, number])
Adds a title for the diagram (top-center). -
addAxisUnits(xLineCoord: Position, yLinceCoord: Position)
Adds Text for axis-units at the end of the axes. -
addHorizontalLines(stringLengthMultiplier: number, length: number)
Adds horizontal lines to the bar diagram of a certain length, andstringLengthMultiplier
is used for calculating the distance of the Text displaying the value of the line from the y-axis.-
addHorizontalLine(y: number, numOfDigits: number, length: number, stringLengthMultiplier: number)
Adds a Line at y-coordinate y, displays the value of the line fixed tonumOfDigits
digits.
-
-
-
setColorForBar(barIndex: number, color?: number)
Takes in the index of the bar (the number in the order of the bars visible on-screen) and changes its color. -
switchBars(barIndex1: number, barIndex2: number)
Takes in the index of two bars as in the method explained above, and switches their positions. -
roundToNiceNumber(num: number) : number
Helper-function to round a number based on the two most significant digits (304 => 300, 19 => 20...). -
hasNegativeBar(): boolean
Helper-function for calculating placement of title of x-axis