In this article you will learn about customizing charts and data table using Adhoc of Helical Insight.
In Adhoc, a user can generate various reports such as :
- Tabular Report
- Chart Report
- Axis Based chart
- Non-Axis Based chart
- Cross-Tabular Report
Following are some of the customization which can be applied on table, charts and Cross-Tab :
Table Customization
Sr No | Customization Name | SubCategory | JavaScript Code | CSS Style Code | both code mandatory |
---|---|---|---|---|---|
1 | Header Color Change | $('th').css({"background-color": "plum"}); | .table > thead > tr > th{ background-color: plum; } | no, you can use either | |
2 | Row Banding | Remove | $('table').removeClass('table-striped'); | no | |
3 | Background Color Change | $("table").on("loaded.rs.jquery.bootgrid", function(){ $('tbody > tr').css({"background-color": "grey"}); }); | .table > tbody > tr > td{ background-color: thistle; } | yes | |
4 | Table Border | remove table border, define width size, define color | .table > tbody > tr > td, .table > thead > tr > th { border: none; border-bottom: 1px solid #DDD; } /** allows to remove the table borders, define its width size, define its color **/ | no | |
5 | Table Partition | remove | hi_container.set("postExecution", function () { $('table').removeClass('table-bordered'); }); | .table > tbody > tr > td, .table > thead > tr > th { border: none; border-bottom: 1px solid #DDD; } | either |
6 | Table Text | Change color, Size and font | $('table').css({"color" : "green", "font-size":"15px", "font-family":"Serif"}); | .table > tbody > tr > td{ color : red; font-size : 15px; font-family : Consolas; } | either |
7 | Row Banding | Add | Odd: .table > tbody > tr:nth-child(2n+1)> td, .table-sticky.table-striped > tbody > tr:nth-of-type(2n+1)> td{ background-color: palegreen; } | either | |
Even: .table > tbody > tr:nth-child(2n)>td, .table-sticky.table-striped > tbody > tr:nth-of-type(2n)> td { background-color: moccasin; } | |||||
8 | Defining Row Count | Add | $("#chart").bootgrid("destroy"); $("#chart").bootgrid({rowCount : 15}); | script | |
9 | Column Banding | Add | odd:- .table > tbody > tr > td:nth-child(2n+1), .table > thead > tr > th:nth-child(2n+1){ background-color: yellow; } even:- .table > tbody > tr > td:nth-child(2n), .table > thead > tr > th:nth-child(2n){ background-color: blue; } | css / script | |
10 | Chess Pattern | .table > tbody > tr:nth-child(2n) > td:nth-child(2n), .table > tbody > tr:nth-child(2n + 1) > td:nth-child(2n + 1){ background:#000; color: #FFFFFF; font-weight: bold; } | css / script | ||
11 | Shadow to a table | Add | //Table-Shadow .table { box-shadow: 10px 10px 5px #888888 } | ||
12 | Heading and Sub-heading | Add | hi_container.set("postExecution", function () { $('#main').prepend(' Sub-Heading$('#main').prepend(' Heading}); | .heading{ text-align : center; color: green; font-size: 20px; } .subheading{ text-align : center; color: green; font-size: 20px; } | Yes |
Axis Chart Customization
Sr No | Customization Name | Sub Category | JavaScript Code | CSS Style Code | both code mandatory |
---|---|---|---|---|---|
1 | Chart Resizing | add | $(document).ready(function(){ Hdi.c3chart.resize({ height: 400, width: 900 }); }); | no | |
2 | Axis label color | add | .c3-axis-x > .tick{ fill:green; } .c3-axis-y > .tick{ fill: red; } | no | |
3 | Axis label color | remove / hide | .c3-axis-x > .tick{ fill: none; } .c3-axis-y > .tick{ fill: none; } | no | |
3 | Axis Line Color | add | .c3 .c3-axis-x path, .c3 .c3-axis-x line { stroke: green; //stroke: none; - hides axis } .c3 .c3-axis-y path, .c3 .c3-axis-y line { stroke: red; //stroke: none; - hides axis } | ||
4 | Remove Axis Line | remove or Hide | .c3 .c3-axis-x path, .c3 .c3-axis-x line { stroke: none; } .c3 .c3-axis-y path, .c3 .c3-axis-y line { stroke: none; } | ||
5 | Axis Label Formatting | Add | .c3-axis-y > .tick { fill: red; font-style: italic; font-family: "Times New Roman"; font-size: 15px; } .c3-axis-x > .tick { fill: green; font-style: oblique; font-family: "Times New Roman"; font-size: 15px; } // font size, font styles and font size | ||
14 | Axis Label rename | rename | hi_container.set("postExecution", function () { Hdi.c3chart.axis.labels({ x: 'Destination place', y: 'Number of Travels' }); }); | ||
15 | Axis Legend rename | rename | hi_container.set("postExecution", function () { Hdi.c3chart.data.names({ "min_Cost": 'New Name 1', "Travel Count" : 'Count of Travel' }); }); | ||
6 | Change Background | Add | hi_container.set("postExecution", function () { $('g.c3-chart > g.c3-event-rects').removeAttr('style'); }); | g.c3-chart > g.c3-event-rects{ fill:yellow; } | Yes |
7 | Making Chart Transparent | hi_container.set("postExecution", function () { $('.c3').css('opacity','0.3'); }); | No | ||
8 | Heading and Sub-heading | Add | hi_container.set("postExecution", function () { $('#main').prepend(' Sub-Heading$('#main').prepend(' Heading}); | .heading{ text-align : center; color: green; font-size: 20px; } .subheading{ text-align : center; color: green; font-size: 20px; } | Yes |
9 | Change Chart Color | Add | hi_container.set("postExecution", function () { Hdi.c3chart.data.colors({ "Travel Count" : 'Plum' }); }); | ||
10 | Grid Lines (Y-Axis) | Add | hi_container.set("postExecution", function () { Hdi.c3chart.ygrids.add([ {value: 20,class:'grid1', text: 'Minimum'}, {value: 40, class:'grid2',text: 'Maximum'} ]); }); // customization of the text and the gridlines | .c3-ygrid-line.grid1 line { stroke: red; } .c3-ygrid-line.grid1 text{ fill: red; font-size: 10px; } .c3-ygrid-line.grid2 line { stroke: green; } .c3-ygrid-line.grid2 text{ fill: green; font-size: 10px; } | |
Remove | hi_container.set("postExecution", function () { Hdi.c3chart.ygrids.remove([ {value: 26}, ]); }); | ||||
11 | Grid Lines (X-Axis) | Add | hi_container.set("postExecution", function () { Hdi.c3chart.xgrids.add([ {value: 20,class:'xgrid0', text: 'Minimum'}, {value: 40, class:'xgrid1',text: 'Maximum'}, ]); }); | .c3-xgrid-line.xgrid0 line { stroke: black; } .c3-xgrid-line.xgrid0 text { fill: black; font-size: 10px; } .c3-xgrid-line.xgrid1 line { stroke: #EFE11A; } .c3-xgrid-line.xgrid1 text { fill: #EFE11A; font-size: 10px; } | |
Grid Lines (X-Axis) | Remove1 (Selected) | hi_container.set("postExecution", function () { Hdi.c3chart.xgrids.remove([ {value: 'Chandigarh'}, ]); }); | |||
12 | Highlight Region | Add | hi_container.set("postExecution", function () { Hdi.c3chart.regions.add( {axis: 'x', start: 1, end: 2, class: 'regionX'}), Hdi.c3chart.regions.add( {axis: 'y', start: 20, end: 40, class: 'regionY'} ); }); // then add the CSS | .c3-region.regionY { fill: red; } .c3-region.regionX { fill: green; } | |
Highlight Region | Remove1 (selected) | hi_container.set("postExecution", function () { Hdi.c3chart.regions.remove( {classes: ['regionX', 'regionY']} ); }); | |||
13 | Hide Fields | hide | setTimeout(function () { // data1 will be hidden. Hdi.c3chart.hide('data1'); // data1 and data2 will be hidden. Hdi.c3chart.hide(['data1', 'data2']); // all targets will be hidden. Hdi.c3chart.hide(); // data1 will be hidden together with its legend. Hdi.c3chart.hide('data1', {withLegend: true}); }); }, 200); | ||
Hide Fields | hide | hi_container.set("postExecution", function () { Hdi.c3chart.hide("Travel Count"); }); | |||
16 | Set Axis range | add | hi_container.set("postExecution", function () { Hdi.c3chart.axis.range({ min: { x: -2, y: -150 }, max: { x: 20, y: 200 } }); }); | ||
17 | Set Background color and opacity | add | hi_container.set("postExecution", function () { $('g.c3-event-rects').css("fill-opacity", "0.2").css("fill", "yellow"); }); | ||
18 | Data Points | remove | hi_container.set("postExecution", function () { Hdi.c3chart.unload({ ids: ['Abbas', 'Aliqui'] }); }); | ||
19 | Chart Transformation | Add | hi_container.set("postExecution", function () { Hdi.c3chart.transform('bar', 'Travel Count' ); Hdi.c3chart.transform('line', 'Cost of Travel' ); Hdi.c3chart.data.colors({ "Cost of Travel" : '#ff7f0e' ,"Travel Count" : '#2ca02c' }); }); | ||
20 | Axis Tick Rotate | Add | hi_container.set("postExecution", function () { $('.c3-axis-x .tick text').attr('transform','rotate(-90)').css('text-anchor','end'); }); | ||
21 | Chart Thickness | Add | .c3-line{ stroke-width:5px; } | ||
22 | Data Points Color Change | Add (conditional basis) | Hdi.c3chart.data.colors({ 'data1': function(d) { return (d.value >= 7) ? '#00ff00': '#ff0000'; } }); | ||
23 | Axis Line ( X & Y axis) | Hide | .c3 .c3-axis-x path, .c3 .c3-axis-x line { stroke: none; } .c3 .c3-axis-y path, .c3 .c3-axis-y line { stroke: none; } | ||
24 | Line Color (line Chart) | Add | .c3-line{ stroke-width:5px; stroke: yellow !important; } | ||
25 | Chart Transform Continuously | Changing charts continuously - hi_container.set("postExecution", function () { //set initial chart colour Hdi.c3chart.data.colors({ 'Number of Employees': '#1FAF96' }); //Map for chart type var typeMap = { "1" : "bar", "2" : "line", "3" : "area", "4" : "spline", "5" : "area-step" }; //Map for different colors per chart type var colorMap = { "1" : "#A9ACE3", "2" : "#E1A9D6", "3" : "#84DFED", "4" : "#EDE588", "5" : "#8CDA94" }; var cntr = 1; function change(){ var changeIt = setInterval(function(){ cntr++; if(cntr > 5){ cntr = 1; } //Change the chart type Hdi.c3chart.transform(typeMap[cntr]); //Change the chart color Hdi.c3chart.data.colors({ 'Number of Employees': colorMap[cntr] }); },1500); //set time to wait before the transform. }; change(); }); |
Non-Axis Chart Customization
Sr No | Customization Name | Sub-Category | JavaScript Code | CSS Style Code | both code mandatory |
---|---|---|---|---|---|
1 | Heading and Sub-heading | Add | setTimeout(function () { d3.select('#chart svg').append('text') .attr('x', d3.select('#chart svg').node().getBoundingClientRect().width / 2) .attr('y', 8) .attr('text-anchor', 'middle') .attr('id', 'heading') .text('Gender wise Distribution') }, 200); | either | |
2 | opacity | $(document).ready(function(){ $('.c3').css('opacity','0.2') ; }); | |||
3 | background color | Add | $(document).ready(function(){ $('.c3').css('background','yellow') ; }); | body{ background:#fffacd; } | either |
Cross-Tab Customization
Sr No | Customization Name | Sub-Category | JavaScript Code | CSS Style Code | both code mandatory |
---|---|---|---|---|---|
1 | Conditional Formatting (Applicable for only column) | Add | hi_container.set("postExecution", function(){ function checker(table){ [].forEach.call(table.rows, function(row, i){ if (i===0) return; [].forEach.call(row.cells, function(cell, i){ var cellData = cell.innerHTML.replace(/,/g , ""); var val = parseInt(cellData); if(val >= 50000) cell.style.backgroundColor = 'red'; if(val >= 20000 && val<50000) cell.style.backgroundColor = 'orange'; if(val < 20000) cell.style.backgroundColor = 'yellow'; }); }); }; var table = document.querySelectorAll(".table"); [].forEach.call(table, checker); }); | .hi-pvtTotal, .hi-pvtGrandTotal{ background:none !important; } | require |
2 | Cross Tab HeatMap | Add | hi_container.set("postExecution", function(){ function Interpolate(start, end, steps, count) { var s = start, e = end, final = s + (((e - s) / steps) * count); return Math.floor(final); } function Color(_r, _g, _b) { var r, g, b; var setColors = function(_r, _g, _b) { r = _r; g = _g; b = _b; }; setColors(_r, _g, _b); this.getColors = function() { var colors = { r: r, g: g, b: b }; return colors; }; } function checker(table){ var valArr = []; var cellData; var val; [].forEach.call(table.rows, function(row, i){ if (i===0) return; [].forEach.call(row.cells, function(cell, i){ cellData = cell.innerHTML.replace(/,/g , ""); val = parseInt(cellData); if(!isNaN(val)) valArr.push(val); valArr.sort(function(a, b){return a-b}); }); }); [].forEach.call(table.rows, function(row, i){ if (i===0) return; [].forEach.call(row.cells, function(cell, i){ red = new Color(255, 0, 0), white = new Color(255, 255, 255), start = white, end = red; cellData = cell.innerHTML.replace(/,/g , ""); val = parseInt(cellData); var count = 2+valArr.indexOf(val); var startColors = start.getColors(), endColors = end.getColors(); var r = Interpolate(startColors.r, endColors.r, valArr.length, count); var g = Interpolate(startColors.g, endColors.g, valArr.length, count); var b = Interpolate(startColors.b, endColors.b, valArr.length, count); if(!isNaN(val)) cell.style.backgroundColor = "rgb(" + r + "," + g + "," + b + ")"; }); }); }; var table = document.querySelectorAll(".table"); [].forEach.call(table, checker); }); | // to not color the totals // .hi-pvtTotal, .hi-pvtGrandTotal { // background: none !important; // } | may require / may not require |
3 | Heading and Sub-heading | Add | hi_container.set("postExecution", function () { $('#main').prepend(' Sub-Heading$('#main').prepend(' Heading}); | .heading{ text-align : center; color: green; font-size: 20px; } .subheading{ text-align : center; color: green; font-size: 20px; } | Yes |
In case of issue, post your queries on forum