Obsidian/Recognition/Work Related/프로젝트/스마트계류장/1.데이터베이스/통계관련/통계화면 초안 차트.md

523 lines
11 KiB
Markdown
Raw Normal View History

2023-08-14 16:19:25 +00:00
```javascript
SFR-25 Hot Spot 지점 교통량
https://www.chartjs.org/docs/latest/samples/bar/stacked.html
const config = {
type: 'bar',
data: data,
options: {
plugins: {
title: {
display: true,
text: 'Hot Spot 지점 교통량'
},
},
responsive: true,
scales: {
x: {
stacked: true,
},
y: {
stacked: true
}
}
}
};
const DATA_COUNT = 12;
const NUMBER_CFG = {count: DATA_COUNT, min: 0, max: 100};
const labels = Utils.months({count: 12});
const data = {
labels: labels,
datasets: [
{
label: 'Spot1',
data: Utils.numbers(NUMBER_CFG),
backgroundColor: Utils.CHART_COLORS.red,
},
{
label: 'Spot2',
data: Utils.numbers(NUMBER_CFG),
backgroundColor: Utils.CHART_COLORS.blue,
},
{
label: 'Spot3',
data: Utils.numbers(NUMBER_CFG),
backgroundColor: Utils.CHART_COLORS.green,
},
{
label: 'Spot4',
data: Utils.numbers(NUMBER_CFG),
backgroundColor: Utils.CHART_COLORS.yellow,
},
]
};
------------------------------------------------------------------------------------------
SFR-25 Gate별 사용량
https://www.chartjs.org/docs/latest/samples/scales/time-combo.html
const config = {
type: 'line',
data: data,
options: {
plugins: {
title: {
text: 'Gate별 사용량 (TOP 10)',
display: true
}
},
},
};
const DATA_COUNT = 10;
const NUMBER_CFG = {count: DATA_COUNT, min: 0, max: 100};
const labels = [];
for (let i = 0; i < DATA_COUNT; ++i) {
labels.push('Gete' + (i +1));
}
const data = {
labels: labels,
datasets: [{
type: 'bar',
label: '계류장IN',
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.red, 0.5),
borderColor: Utils.CHART_COLORS.red,
data: Utils.numbers(NUMBER_CFG),
}, {
type: 'bar',
label: '계류장OUT',
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.blue, 0.5),
borderColor: Utils.CHART_COLORS.blue,
data: Utils.numbers(NUMBER_CFG),
}, {
type: 'line',
label: '사용량',
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.green, 0.5),
borderColor: Utils.CHART_COLORS.green,
fill: false,
data: Utils.numbers(NUMBER_CFG),
}]
};
------------------------------------------------------------------------------------------
SFR-25 유도로 구간별 점유시간 및 사용량
https://www.chartjs.org/docs/latest/samples/scales/linear-min-max-suggested.html
const config = {
type: 'bar',
data: data,
options: {
plugins: {
title: {
display: true,
text: '유도로 구간별 점유시간 및 사용량'
},
},
responsive: true,
scales: {
x: {
stacked: true,
},
y: {
stacked: true
}
}
}
};
const DATA_COUNT = 12;
const NUMBER_CFG = {count: DATA_COUNT, min: 0, max: 100};
const labels = Utils.months({count: 12});
const data = {
labels: labels,
datasets: [
{
label: 'R7 사용량',
data: [10, 30, 39, 20, 25, 34, 10, 11, 12, 14, 16, 21],
borderColor: Utils.CHART_COLORS.red,
backgroundColor: Utils.CHART_COLORS.red,
type: 'line',
},
{
label: 'R11 사용량',
data: [18, 33, 22, 19, 11, 39, 30, 21, 22, 24, 26, 31],
borderColor: Utils.CHART_COLORS.blue,
backgroundColor: Utils.CHART_COLORS.blue,
type: 'line',
},
{
type: 'bar',
label: 'R7 점유시간',
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.red, 0.5),
borderColor: Utils.CHART_COLORS.red,
data: Utils.numbers(NUMBER_CFG),
},
{
type: 'bar',
label: 'R11 점유시간',
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.green, 0.5),
borderColor: Utils.CHART_COLORS.red,
data: Utils.numbers(NUMBER_CFG),
},
]
};
------------------------------------------------------------------------------------------
SFR-25 기종별 유도로 이동시간
const config = {
type: 'bar',
data: data,
options: {
indexAxis: 'y',
// Elements options apply to all of the options unless overridden in a dataset
// In this case, we are setting the border of each horizontal bar to be 2px wide
elements: {
bar: {
borderWidth: 2,
}
},
responsive: true,
plugins: {
legend: {
position: 'right',
},
title: {
display: true,
text: '주요 기종별 유도로 이동시간'
}
}
},
};
const DATA_COUNT = 10;
const NUMBER_CFG = {count: DATA_COUNT, min: 0, max: 120};
const labels = [];
labels.push('A220');
labels.push('A321');
labels.push('A220');
labels.push('A330');
labels.push('B737');
labels.push('B747');
labels.push('B777');
const data = {
labels: labels,
datasets: [
{
label: 'R1',
data: Utils.numbers(NUMBER_CFG),
borderColor: Utils.CHART_COLORS.red,
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.red, 0.5),
},
{
label: 'R2',
data: Utils.numbers(NUMBER_CFG),
borderColor: Utils.CHART_COLORS.blue,
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.blue, 0.5),
},
{
label: 'R3',
data: Utils.numbers(NUMBER_CFG),
borderColor: Utils.CHART_COLORS.blue,
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.green, 0.5),
}
]
};
------------------------------------------------------------------------------------------
SFR-25 제방빙 사용시간
https://www.chartjs.org/docs/latest/samples/line/line.html
const config = {
type: 'line',
data: data,
options: {
responsive: true,
plugins: {
legend: {
position: 'top',
},
title: {
display: true,
text: '제방빙 사용시간(Pad별)'
}
}
},
};
const DATA_COUNT = 8;
const NUMBER_CFG = {count: DATA_COUNT, min: 0, max: 100};
const labels = Utils.months({count: 8});
const data = {
labels: labels,
datasets: [
{
label: 'Pad1',
data: Utils.numbers(NUMBER_CFG),
borderColor: Utils.CHART_COLORS.red,
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.red, 0.5),
},
{
label: 'Pad2',
data: Utils.numbers(NUMBER_CFG),
borderColor: Utils.CHART_COLORS.blue,
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.blue, 0.5),
}
,
{
label: 'Pad3',
data: Utils.numbers(NUMBER_CFG),
borderColor: Utils.CHART_COLORS.green,
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.green, 0.5),
}
]
};
------------------------------------------------------------------------------------------
SFR-25 관제사별 근무시간 및 관제량(항공기 대수)
https://www.chartjs.org/docs/latest/samples/line/line.html
const config = {
type: 'line',
data: data,
options: {
responsive: true,
plugins: {
legend: {
position: 'top',
},
title: {
display: true,
text: '관제사별 근무시간 및 관제량(항공기 대수)'
}
}
},
};
const DATA_COUNT = 8;
const NUMBER_CFG = {count: DATA_COUNT, min: 0, max: 100};
const labels = Utils.months({count: 8});
const data = {
labels: labels,
datasets: [
{
label: '관제사1',
data: Utils.numbers(NUMBER_CFG),
borderColor: Utils.CHART_COLORS.red,
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.red, 0.5),
},
{
label: '관제사2',
data: Utils.numbers(NUMBER_CFG),
borderColor: Utils.CHART_COLORS.blue,
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.blue, 0.5),
}
,
{
label: '관제사3',
data: Utils.numbers(NUMBER_CFG),
borderColor: Utils.CHART_COLORS.green,
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.green, 0.5),
}
]
};
CONfig
import colorLib from '@kurkle/color';
import {DateTime} from 'luxon';
import 'chartjs-adapter-luxon';
import {valueOrDefault} from '../../dist/helpers.js';
// Adapted from http://indiegamr.com/generate-repeatable-random-numbers-in-js/
var _seed = Date.now();
export function srand(seed) {
_seed = seed;
}
export function rand(min, max) {
min = valueOrDefault(min, 0);
max = valueOrDefault(max, 0);
_seed = (_seed * 9301 + 49297) % 233280;
return min + (_seed / 233280) * (max - min);
}
export function numbers(config) {
var cfg = config || {};
var min = valueOrDefault(cfg.min, 0);
var max = valueOrDefault(cfg.max, 100);
var from = valueOrDefault(cfg.from, []);
var count = valueOrDefault(cfg.count, 8);
var decimals = valueOrDefault(cfg.decimals, 8);
var continuity = valueOrDefault(cfg.continuity, 1);
var dfactor = Math.pow(10, decimals) || 0;
var data = [];
var i, value;
for (i = 0; i < count; ++i) {
value = (from[i] || 0) + this.rand(min, max);
if (this.rand() <= continuity) {
data.push(Math.round(dfactor * value) / dfactor);
} else {
data.push(null);
}
}
return data;
}
export function points(config) {
const xs = this.numbers(config);
const ys = this.numbers(config);
return xs.map((x, i) => ({x, y: ys[i]}));
}
export function bubbles(config) {
return this.points(config).map(pt => {
pt.r = this.rand(config.rmin, config.rmax);
return pt;
});
}
export function labels(config) {
var cfg = config || {};
var min = cfg.min || 0;
var max = cfg.max || 100;
var count = cfg.count || 8;
var step = (max - min) / count;
var decimals = cfg.decimals || 8;
var dfactor = Math.pow(10, decimals) || 0;
var prefix = cfg.prefix || '';
var values = [];
var i;
for (i = min; i < max; i += step) {
values.push(prefix + Math.round(dfactor * i) / dfactor);
}
return values;
}
const MONTHS = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
];
export function months(config) {
var cfg = config || {};
var count = cfg.count || 12;
var section = cfg.section;
var values = [];
var i, value;
for (i = 0; i < count; ++i) {
value = MONTHS[Math.ceil(i) % 12];
values.push(value.substring(0, section));
}
return values;
}
const COLORS = [
'#4dc9f6',
'#f67019',
'#f53794',
'#537bc4',
'#acc236',
'#166a8f',
'#00a950',
'#58595b',
'#8549ba'
];
export function color(index) {
return COLORS[index % COLORS.length];
}
export function transparentize(value, opacity) {
var alpha = opacity === undefined ? 0.5 : 1 - opacity;
return colorLib(value).alpha(alpha).rgbString();
}
export const CHART_COLORS = {
red: 'rgb(255, 99, 132)',
orange: 'rgb(255, 159, 64)',
yellow: 'rgb(255, 205, 86)',
green: 'rgb(75, 192, 192)',
blue: 'rgb(54, 162, 235)',
purple: 'rgb(153, 102, 255)',
grey: 'rgb(201, 203, 207)'
};
const NAMED_COLORS = [
CHART_COLORS.red,
CHART_COLORS.orange,
CHART_COLORS.yellow,
CHART_COLORS.green,
CHART_COLORS.blue,
CHART_COLORS.purple,
CHART_COLORS.grey,
];
export function namedColor(index) {
return NAMED_COLORS[index % NAMED_COLORS.length];
}
export function newDate(days) {
return DateTime.now().plus({days}).toJSDate();
}
export function newDateString(days) {
return DateTime.now().plus({days}).toISO();
}
export function parseISODate(str) {
return DateTime.fromISO(str);
}
```