Repository navigation
Expand file tree
/
Copy pathFullBarChart.js
More file actions
134 lines (111 loc) · 4.53 KB
/
Copy pathFullBarChart.js
File metadata and controls
134 lines (111 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/// <reference path="Scripts/jschart-vsdoc.js" />
var Charting = MindFusion.Charting;
var Controls = Charting.Controls;
var Collections = MindFusion.Common.Collections;
var Drawing = MindFusion.Drawing;
var ToolTip = Charting.ToolTip;
var chartEl = document.getElementById('barChart');
chartEl.width = chartEl.offsetParent.clientWidth;
chartEl.height = chartEl.offsetParent.clientHeight;
var chart = new Controls.BarChart(chartEl, Charting.BarLayout.Stack);
chart.horizontalBars = true;
chart.barSpacingRatio = 0.2;
chart.allowZoom = false;
chart.allowPan = false;
chart.innerLabelRotation = 0;
chart.titleMargin = new Charting.Margins(0, 20, 0, 20);
chart.title = "WHAT MATTERS WHEN YOU CHOOSE A NEW JOB?";
//legend
chart.legendMargin = new Charting.Margins(10, 10, 10, 10);
chart.showLegend = true;
chart.showLegendTitle = false;
// a custom series class
class SeriesWithLabels extends Charting.BarSeries {
constructor(barValues, innerLabels, yLabels) {
super(barValues, innerLabels, null, yLabels);
this._yLabels = yLabels;
this._innerLabels = innerLabels;
this._values = barValues;
}
getLabel(index, kind) {
if ((kind & Charting.LabelKinds.YAxisLabel) != 0 && this._yLabels)
return this._yLabels.item(index);
if ((kind & Charting.LabelKinds.InnerLabel) != 0 && this._innerLabels)
return this._innerLabels.item(index).toString();
if ((kind & Charting.LabelKinds.ToolTip) != 0)
return getPercentLabel(index, this);
return super.getLabel(index, kind);
}
}
function getPercentLabel(index, series) {
var val1 = series1.values.item(index);
var val2 = series2.values.item(index);
var val3 = series3.values.item(index);
var total = val1 + val2 + val3;
var current = series.values.item(index);
var result = (current / total) * 100;
return Number(result).toFixed(0) + "%";
}
var labels = new Collections.List([
"POSITION", "SALARY", "LOCATION", "COLLEAGUES", "WORKTIME"
]);
// series with the custom class
var series1 = new SeriesWithLabels(
new Collections.List([123, 212, 220, 115, 0.01]),
new Collections.List([123, 212, 220, 115, 0]),
labels
);
var series2 = new SeriesWithLabels(
new Collections.List([53, 132, 42, 105, 80]),
new Collections.List([53, 132, 42, 105, 80]),
null
);
var series3 = new SeriesWithLabels(
new Collections.List([224, 56, 138, 180, 320]),
new Collections.List([224, 56, 138, 180, 320]),
null
);
series1.supportedLabels = Charting.LabelKinds.YAxisLabel | Charting.LabelKinds.InnerLabel | Charting.LabelKinds.ToolTip;
series2.supportedLabels = Charting.LabelKinds.InnerLabel | Charting.LabelKinds.ToolTip;
series3.supportedLabels = Charting.LabelKinds.InnerLabel | Charting.LabelKinds.ToolTip;
var series = new Collections.ObservableCollection([series1, series2, series3]);
series.item(0).title = "CAREER START";
series.item(1).title = "MIDDLE OF CAREER";
series.item(2).title = "CAREER END";
chart.series = series;
// chart styling through the theme property
chart.theme.gridColor1 = chart.theme.gridColor2 = new Drawing.Color("#ffffff");
chart.theme.gridLineColor = new Drawing.Color("#eceff1");
chart.theme.axisStroke = new Drawing.Brush("transparent");
chart.theme.axisLabelsBrush = new Drawing.Brush("#455a64");
chart.theme.dataLabelsBrush = new Drawing.Brush("#ffffff");
chart.theme.legendBackground = new Drawing.Brush("#455a64");
chart.theme.legendBorderStroke = new Drawing.Brush("#37474f");
chart.theme.legendTitleBrush = new Drawing.Brush("#ffffff");
chart.theme.legendLabelsBrush = new Drawing.Brush("#ffffff");
chart.theme.highlightStroke = new Drawing.Brush("#ffa000");
chart.theme.highlightStrokeThickness = 3;
// style the tooltip
ToolTip.brush = new Drawing.Brush("#ffffff");
ToolTip.pen = new Drawing.Pen("#cfd8dc");
ToolTip.textBrush = new Drawing.Brush("#37474f");
ToolTip.horizontalPadding = 12;
ToolTip.verticalPadding = 8;
// colour palette
var firstBrush = new Drawing.Brush("#26a69a"); // Teal
var secondBrush = new Drawing.Brush("#3f51b5"); // Indigo
var thirdBrush = new Drawing.Brush("#ffa000"); // Amber
chart.plot.seriesStyle = new Charting.PerSeriesStyle(
new Collections.List([firstBrush, secondBrush, thirdBrush]),
new Collections.List([firstBrush, secondBrush, thirdBrush]),
new Collections.List([1, 1, 1])
);
chart.showXCoordinates = false;
chart.showYCoordinates = false;
chart.showXTicks = false;
chart.showYTicks = false;
chart.xAxis.interval = 1;
chart.xAxis.title = "";
chart.yAxis.title = "";
chart.gridType = Charting.GridType.None;
chart.draw();