Skip to content

3.4.1 BarDiagram

Kristiantvaa edited this page Jul 3, 2024 · 10 revisions

BarDiagram


Extends:

Parameters

Required:

  • data: number[] The data to plot
  • labels: string[] The labels corresponding to each bar
  • xAxisTitle: string
  • yAxisTitle: string

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

Methods

  • createBarDiagram() Calls all the add-functions to create the diagram
  • addBars() : number Adds all the bars(Polygons) with Text for the corresponding data-value and labels-value. Returns the end-position of the bars horizontally
  • addAxes(xAxisEnd: number, stringLengthMultiplier: number) Adds two Lines as axes. xAxisEnd is used for calculating the length of the x-axis, and the stringLengthMultiplier is used for calculating the distance of the axis-title from the axis-line
  • 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, and stringLengthMultiplier 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 to numOfDigits 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 it color to color
  • switchBars(barIndex1: number, barIndex2: number) Takes in the index of two bars as in the method explained above. Switches their positions.
  • roundToNiceNumber(num: number) : number Helper-function to round a number based on the two most significant digits (304 => 300, 19 => 20...)
Clone this wiki locally