Skip to content

Commit

Permalink
Add line and bar chart, edit sql
Browse files Browse the repository at this point in the history
  • Loading branch information
stasbamiza committed Oct 21, 2016
1 parent 937ae99 commit 99e1ed2
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 2 deletions.
15 changes: 15 additions & 0 deletions modules/admin/src/amcharts/images/dragIconRoundBig.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions modules/admin/src/amcharts/images/lens.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions modules/admin/src/app/dashboards/chart/lineChart.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ export class LineChart {
chart.zoomChart();
}

console.log(res);

this.chart.dataProvider = res;
this.chart.validateData();
});
Expand Down
100 changes: 100 additions & 0 deletions modules/admin/src/app/dashboards/chart/lineChart.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export class LineChartService {

case 'Pie chart':
return this.getPie(data);

case 'Line chart':
return this.getLine(data);

case 'Bar chart':
return this.getBar(data);
}
}

Expand Down Expand Up @@ -116,4 +122,98 @@ export class LineChartService {
}
}
}

getLine(data: Object) {
return {
"type": "serial",
"theme": "light",
"marginTop":0,
"marginRight": 80,
"dataProvider": data,
"valueAxes": [{
"axisAlpha": 0,
"position": "left"
}],
"graphs": [{
"id":"g1",
"balloonText": "[[category]]<br><b><span style='font-size:14px;'>[[value]]</span></b>",
"bullet": "round",
"bulletSize": 8,
"lineColor": "#d1655d",
"lineThickness": 2,
"negativeLineColor": "#637bb6",
"type": "smoothedLine",
"valueField": "value"
}],
"chartScrollbar": {
"graph":"g1",
"gridAlpha":0,
"color":"#888888",
"scrollbarHeight":55,
"backgroundAlpha":0,
"selectedBackgroundAlpha":0.1,
"selectedBackgroundColor":"#888888",
"graphFillAlpha":0,
"autoGridCount":true,
"selectedGraphFillAlpha":0,
"graphLineAlpha":0.2,
"graphLineColor":"#c2c2c2",
"selectedGraphLineColor":"#888888",
"selectedGraphLineAlpha":1

},
"chartCursor": {
"categoryBalloonDateFormat": "YYYY",
"cursorAlpha": 0,
"valueLineEnabled":true,
"valueLineBalloonEnabled":true,
"valueLineAlpha":0.5,
"fullWidth":true
},
"dataDateFormat": "YYYY",
"categoryField": "year",
"categoryAxis": {
"minPeriod": "YYYY",
"parseDates": true,
"minorGridAlpha": 0.1,
"minorGridEnabled": true
},
"export": {
"enabled": true
}
}
}

getBar(data: Object) {
return {
"type": "serial",
"theme": "light",
"dataProvider": data,
"gridAboveGraphs": true,
"startDuration": 1,
"graphs": [ {
"balloonText": "[[category]]: <b>[[value]]</b>",
"fillAlphas": 0.8,
"lineAlpha": 0.2,
"type": "column",
"valueField": "visits"
} ],
"chartCursor": {
"categoryBalloonEnabled": false,
"cursorAlpha": 0,
"zoomable": false
},
"categoryField": "country",
"categoryAxis": {
"gridPosition": "start",
"gridAlpha": 0,
"tickPosition": "start",
"tickLength": 20
},
"export": {
"enabled": true
}

}
}
}
6 changes: 6 additions & 0 deletions modules/core/src/main/resources/db/migration/1472473094.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ if ($Dashboard.size() == 0) {
let statusType = INSERT INTO DashboardBoxType SET name = 'Ivan feeds', type = 'status', kind = 'Feedback status', code = '', codeLanguage = 'SQL'
let pieChartType = INSERT INTO DashboardBoxType SET name = 'Petia profit', type = 'chart', kind = 'Pie chart', code = "return {data: \"function generateStr() { var text = ''; var possible = 'abcdefghijklmnopqrstuvwxyz'; for( var i=0; i < 5; i++ ) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } var res = []; var len = Math.ceil(Math.random()*15); for(var i = 0; i < len; i++) { res.push({ country: generateStr(), litres: Math.ceil(Math.random()*100) }); } res;\"}", codeLanguage = 'JavaScript'
let serialChartType = INSERT INTO DashboardBoxType SET name = 'Rusia chart profit', type = 'chart', kind = 'Serial chart', code = "return {data: \"let res = []; for (let i = 1; i <= 12; i++) { for (let y = 1; y <= 2; y++) { res.push({ date: new Date(2016, i, y*5), value: Math.ceil(Math.random()*1000), value0: Math.ceil(Math.random()*1000) }); } } res;\"}", codeLanguage = 'JavaScript'
let lineChartType = INSERT INTO DashboardBoxType SET name = 'Ivan chart profit', type = 'chart', kind = 'Line chart', code = "return {data: \"var res = []; for(let i = 1900; i < 2016; i++) { var single = Math.random()*10; single = single > 5 ? 1 : -1; res.push({ year: String(i), value: Math.ceil(Math.random()*100)*single }); } res;\"}", codeLanguage = 'JavaScript'
let barChartType = INSERT INTO DashboardBoxType SET name = 'Kolia chart profit', type = 'chart', kind = 'Bar chart', code = "return {data: \"var res = []; function getStr() { var text = ''; var possible = 'abcdefghijklmnopqrstuvwxyz'; for( var i=0; i < 5; i++ ) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } var len = Math.ceil(Math.random()*50); for(var i = 0; i < len; i++) { res.push({ country: getStr(), visits: Math.ceil(Math.random()*10000) }); } res;\"}", codeLanguage = 'JavaScript'

console.log "Creating process for DashboardBoxType class is done."
}
Expand All @@ -58,6 +60,8 @@ if ($Dashboard.size() == 0) {
let statusType = select * from DashboardBoxType where name = 'Ivan feeds'
let pieChartType = select * from DashboardBoxType where name = 'Petia profit'
let serialChartType = select * from DashboardBoxType where name = 'Rusia chart profit'
let lineChartType = select * from DashboardBoxType where name = 'Ivan chart profit'
let barChartType = select * from DashboardBoxType where name = 'Kolia chart profit'
let defaultDashboard = select * from Dashboard where name = 'default'

CREATE Class DashboardBox
Expand Down Expand Up @@ -87,6 +91,8 @@ if ($Dashboard.size() == 0) {

INSERT INTO DashboardBox SET width = 50, height = 50, order = 5, dashboard = $defaultDashboard['@rid'][0], type = $pieChartType['@rid'][0], name = 'Box 5', description = 'Box 5 desc'
INSERT INTO DashboardBox SET width = 50, height = 50, order = 6, dashboard = $defaultDashboard['@rid'][0], type = $serialChartType['@rid'][0], name = 'Box 6', description = 'Box 6 desc'
INSERT INTO DashboardBox SET width = 50, height = 50, order = 7, dashboard = $defaultDashboard['@rid'][0], type = $lineChartType['@rid'][0], name = 'Box 7', description = 'Box 7 desc'
INSERT INTO DashboardBox SET width = 50, height = 50, order = 8, dashboard = $defaultDashboard['@rid'][0], type = $barChartType['@rid'][0], name = 'Box 8', description = 'Box 8 desc'

console.log "Creating process for DashboardBox class is done."
}
Expand Down

0 comments on commit 99e1ed2

Please sign in to comment.