diagramatics logo Diagramatics GitHub Docs Guides Editor Examples

Bar Options

All the bar function can be configured by passing in bar_options, which is an object with the following properties:
    gap      : number,
    yrange?  : [number, number],
    yticks?  : number[],
    bbox?    : [Vector2, Vector2],
    ticksize : number,
    

Plotting

You can prepare the data in the form of datavalues : number[] and datanames : string[].
let data = [10, 8, 12, 15, 7]; let b = bar.plot(data); draw(b);
bar.plot ( datavalues  :  number[]bar_options?  :  Partial<bar_options> )  :  Diagram
let data = [10, 8, 12, 15, 7]; let b = bar.plot(data); draw(b);
let datanames = ['a', 'b', 'c', 'x', 'ye']; let xx = bar.xaxes(datanames); draw(xx);
bar.xaxes ( datanames  :  string[]bar_options?  :  Partial<bar_options> )  :  Diagram
let datanames = ['a', 'b', 'c', 'x', 'ye']; let xx = bar.xaxes(datanames); draw(xx);
let data = [10, 8, 12, 15, 7]; let yy = bar.yaxes(data); draw(yy);
bar.yaxes ( datavalues  :  number[]bar_options?  :  Partial<bar_options> )  :  Diagram
let data = [10, 8, 12, 15, 7]; let yy = bar.yaxes(data); draw(yy);

Plot the entire thing

let baropt = { yrange : [0, 20], } let data = [10, 8, 12, 15, 7]; let name = ['orange', 'apple', 'c', 'd', 'ye']; let b = bar.plot(data, baropt).fill('lightblue'); let xx = bar.xaxes(name, baropt).move_origin_text('top-left').textangle(to_radian(30)); let yy = bar.yaxes(data, baropt); draw(b, xx, yy);
let baropt = { yrange : [0, 20], } let data = [10, 8, 12, 15, 7]; let name = ['orange', 'apple', 'c', 'd', 'ye']; let b = bar.plot(data, baropt).fill('lightblue'); let xx = bar.xaxes(name, baropt).move_origin_text('top-left').textangle(to_radian(30)); let yy = bar.yaxes(data, baropt); draw(b, xx, yy);

Interact with standard plot

bar data can be translated into axes_options by setting xrange into [-1, data.length].
let data = [10, 8, 12, 15, 7]; let name = ['a', 'b', 'c', 'd', 'e']; let baropt = { yrange : [0, 20], bbox : [V2(0,0), V2(10,10)], } let axopt = { xrange : [-1, data.length], yrange : baropt.yrange, bbox : baropt.bbox, } let ax_f = axes_transform(axopt); let b = bar.plot(data, baropt).fill('lightblue'); let xx = bar.xaxes(name, baropt); let yy = bar.yaxes(data, baropt); let p = plot(range(0, data.length), data, axopt).strokedasharray([5]); let c = circle(0.2).fill('red').position(ax_f(V2(2, data[2]))); draw(b, xx, yy, p, c);
let data = [10, 8, 12, 15, 7]; let name = ['a', 'b', 'c', 'd', 'e']; let baropt = { yrange : [0, 20], bbox : [V2(0,0), V2(10,10)], } let axopt = { xrange : [-1, data.length], yrange : baropt.yrange, bbox : baropt.bbox, } let ax_f = axes_transform(axopt); let b = bar.plot(data, baropt).fill('lightblue'); let xx = bar.xaxes(name, baropt); let yy = bar.yaxes(data, baropt); let p = plot(range(0, data.length), data, axopt).strokedasharray([5]); let c = circle(0.2).fill('red').position(ax_f(V2(2, data[2]))); draw(b, xx, yy, p, c);