Skip to content

Instantly share code, notes, and snippets.

@ahandsel
Last active December 9, 2020 06:57
Show Gist options
  • Save ahandsel/7ce4e006fae8b635774f9447336c3a50 to your computer and use it in GitHub Desktop.
Save ahandsel/7ce4e006fae8b635774f9447336c3a50 to your computer and use it in GitHub Desktop.

No Server Data Visualization: Build a Bar Chart Race Project!

Thank you for attending our Kintone x Bar Chart Race workshop!

Use the following CSV file, CDN URLs, JavaScript file, and PDF files for the hands-on section!

Download Links

Click here or the Download Zip button on the upper right corner for all the code, data, & slide you need for our workshop!

Getting your FREE Kintone Database

Step 1 - Sign Up for Kintone Developer Account (Website)

  • bit.ly/KDP_signup
    • ⚠ Do NOT use Safari
    • ⚡Accept Cookies First
    • ✅ Use Chrome & Firefox

Step 2 - Create a Kintone Subdomain (Environment)

  • bit.ly/K_DevLic
    • ⚡ Only use lowercase, numbers, & hyphens in your subdomain
    • ⚠ Do not use uppercase nor special characters

Quick video on the sign-up process:

https://youtu.be/Gzz8SbTuoFg https://youtu.be/Gzz8SbTuoFg

Year Manufacturer Phones sold
2005 Apple 0
2005 BlackBerry 0
2005 Coolpad 0
2005 HTC 0
2005 Huawei 0
2005 Lenovo 0
2005 Lenovo Motorola 0
2005 LG 54924600
2005 Micromax 0
2005 Microsoft 0
2005 Motorola 144920400
2005 Nokia 265614800
2005 Samsung 0
2005 Siemens 28590600
2005 Sony 51773800
2005 TCL Communication 0
2005 Xiaomi 0
2005 ZTE 0
2006 Apple 0
2006 BlackBerry 0
2006 Coolpad 0
2006 HTC 0
2006 Huawei 0
2006 Lenovo 0
2006 Lenovo Motorola 0
2006 LG 61986000
2006 Micromax 0
2006 Microsoft 0
2006 Motorola 209250900
2006 Nokia 344915900
2006 Samsung 116480100
2006 Siemens 0
2006 Sony 73641600
2006 TCL Communication 0
2006 Xiaomi 0
2006 ZTE 0
2007 Apple 2300000
2007 BlackBerry 0
2007 Coolpad 0
2007 HTC 0
2007 Huawei 0
2007 Lenovo 0
2007 Lenovo Motorola 0
2007 LG 78576300
2007 Micromax 0
2007 Microsoft 0
2007 Motorola 164307000
2007 Nokia 435453100
2007 Samsung 154540700
2007 Siemens 0
2007 Sony 101358400
2007 TCL Communication 0
2007 Xiaomi 0
2007 ZTE 0
2008 Apple 12000000
2008 BlackBerry 0
2008 Coolpad 0
2008 HTC 0
2008 Huawei 0
2008 Lenovo 0
2008 Lenovo Motorola 0
2008 LG 102555400
2008 Micromax 0
2008 Microsoft 0
2008 Motorola 106590000
2008 Nokia 472315000
2008 Samsung 199182000
2008 Siemens 0
2008 Sony 93414500
2008 TCL Communication 0
2008 Xiaomi 0
2008 ZTE 0
2009 Apple 24889000
2009 BlackBerry 0
2009 Coolpad 0
2009 HTC 0
2009 Huawei 0
2009 Lenovo 0
2009 Lenovo Motorola 0
2009 LG 122055300
2009 Micromax 0
2009 Microsoft 0
2009 Motorola 58475200
2009 Nokia 440881600
2009 Samsung 235772000
2009 Siemens 0
2009 Sony 54873400
2009 TCL Communication 0
2009 Xiaomi 0
2009 ZTE 0
2010 Apple 46598300
2010 BlackBerry 47451600
2010 Coolpad 0
2010 HTC 24688400
2010 Huawei 23814700
2010 Lenovo 0
2010 Lenovo Motorola 0
2010 LG 114154600
2010 Micromax 0
2010 Microsoft 0
2010 Motorola 38553700
2010 Nokia 461318200
2010 Samsung 281065800
2010 Siemens 0
2010 Sony 41819200
2010 TCL Communication 0
2010 Xiaomi 0
2010 ZTE 28768700
2011 Apple 89263200
2011 BlackBerry 51541900
2011 Coolpad 0
2011 HTC 43266900
2011 Huawei 40663400
2011 Lenovo 0
2011 Lenovo Motorola 0
2011 LG 86370900
2011 Micromax 0
2011 Microsoft 0
2011 Motorola 40269000
2011 Nokia 422478300
2011 Samsung 313904200
2011 Siemens 0
2011 Sony 32597500
2011 TCL Communication 0
2011 Xiaomi 0
2011 ZTE 56881800
2012 Apple 130133200
2012 BlackBerry 34210300
2012 Coolpad 0
2012 HTC 32121800
2012 Huawei 47288300
2012 Lenovo 0
2012 Lenovo Motorola 0
2012 LG 58015900
2012 Micromax 0
2012 Microsoft 0
2012 Motorola 33916300
2012 Nokia 333938000
2012 Samsung 384631200
2012 Siemens 0
2012 Sony 0
2012 TCL Communication 37176600
2012 Xiaomi 0
2012 ZTE 67344400
2013 Apple 150785900
2013 BlackBerry 0
2013 Coolpad 32601400
2013 HTC 0
2013 Huawei 53295100
2013 Lenovo 45284700
2013 Lenovo Motorola 0
2013 LG 69024500
2013 Micromax 0
2013 Microsoft 0
2013 Motorola 0
2013 Nokia 250793100
2013 Samsung 444444200
2013 Siemens 0
2013 Sony 37595700
2013 TCL Communication 49531300
2013 Xiaomi 0
2013 ZTE 59898800
2014 Apple 191426000
2014 BlackBerry 0
2014 Coolpad 0
2014 HTC 0
2014 Huawei 70499000
2014 Lenovo 0
2014 Lenovo Motorola 84029000
2014 LG 76096000
2014 Micromax 37094000
2014 Microsoft 185660000
2014 Motorola 0
2014 Nokia 0
2014 Samsung 392546000
2014 Siemens 0
2014 Sony 37791000
2014 TCL Communication 64026000
2014 Xiaomi 56529000
2014 ZTE 53910000
// ⚠️ Order matters when inserting CDN URLs into Kintone App settings
https://www.amcharts.com/lib/4/core.js
https://www.amcharts.com/lib/4/charts.js
https://cdn.amcharts.com/lib/4/themes/animated.js
(function () {
'use strict';
// Kintone event triggered after the record list page is displayed.
kintone.events.on('app.record.index.show', function (event) {
// Retrieve & configure the space element below the record list's header
var spaceDiv = kintone.app.getHeaderSpaceElement();
spaceDiv.style.height = '500px';
spaceDiv.style.marginLeft = '25px';
spaceDiv.style.marginRight = '25px';
spaceDiv.style.border = 'solid';
spaceDiv.style.borderColor = '#ED7B84';
// Automatically enable all amCharts animations
am4core.useTheme(am4themes_animated);
// Create chart instance
var chart = am4core.create(spaceDiv, am4charts.XYChart);
chart.padding(40, 40, 40, 40);
// Shorting numbers by units: K, M, B (Thousands, Millions, Billions)
chart.numberFormatter.bigNumberPrefixes = [{
'number': 1e+3,
'suffix': 'K'
},
{
'number': 1e+6,
'suffix': 'M'
},
{
'number': 1e+9,
'suffix': 'B'
}
];
// The label displaying the year
var label = chart.plotContainer.createChild(am4core.Label);
label.x = am4core.percent(97);
label.y = am4core.percent(95);
label.horizontalCenter = 'right';
label.verticalCenter = 'middle';
label.dx = -15;
label.fontSize = 50;
var stepDuration = 4000;
// Left side content with company names
var categoryAxis = chart.yAxes.push(new am4charts.CategoryAxis());
categoryAxis.renderer.grid.template.location = 0;
categoryAxis.dataFields.category = 'Manufacturer';
categoryAxis.renderer.minGridDistance = 1;
categoryAxis.renderer.inversed = true;
categoryAxis.renderer.grid.template.disabled = true;
// X-axis unit information
var valueAxis = chart.xAxes.push(new am4charts.ValueAxis());
valueAxis.min = 0;
valueAxis.rangeChangeEasing = am4core.ease.linear;
valueAxis.rangeChangeDuration = stepDuration;
valueAxis.extraMax = 0.1;
// Y-axis unit information
var series = chart.series.push(new am4charts.ColumnSeries());
series.dataFields.categoryY = 'Manufacturer';
series.dataFields.valueX = 'value';
series.tooltipText = '{valueX.value}';
series.columns.template.strokeOpacity = 0;
series.columns.template.column.cornerRadiusBottomRight = 5;
series.columns.template.column.cornerRadiusTopRight = 5;
series.interpolationDuration = stepDuration;
series.interpolationEasing = am4core.ease.linear;
// The 'bar' changing shape
var labelBullet = series.bullets.push(new am4charts.LabelBullet());
labelBullet.label.horizontalCenter = 'right';
labelBullet.label.text = '{values.valueX.workingValue.formatNumber(\'#.0as\')}';
labelBullet.label.textAlign = 'end';
labelBullet.label.dx = -10;
chart.zoomOutButton.disabled = true;
// Color is set to columns with chart.colors color set
series.columns.template.adapter.add('fill', function (fill, target) {
return chart.colors.getIndex(target.dataItem.index);
});
var year = 2005;
label.text = year.toString();
var interval;
function play() {
interval = setInterval(function () {
nextYear();
}, stepDuration);
}
function stop() {
if (interval) {
clearInterval(interval);
}
}
// Incrementing the years
function nextYear() {
year++;
if (year > 2014) {
stop();
return;
}
// Only display the Manufacturers with phones sold
var newData = allData[year];
var itemsWithNonZero = 0;
for (var i = 0; i < chart.data.length; i++) {
chart.data[i].value = newData[i].value;
if (chart.data[i].value > 0) {
itemsWithNonZero++;
}
}
// Following two are animation setting using time (in milliseconds) values
// Animating the bars increase/decreasing based on value changes
series.interpolationDuration = stepDuration;
// Animating the zooming in/out on the bars based on the number of bars being displayed
valueAxis.rangeChangeDuration = stepDuration;
// Transition the bars & redraw the graph based on the next years data without complete re-parsing of data
chart.invalidateRawData();
label.text = year.toString();
// Set the current zoom (data range) with the start & end values set between 0 to 1 (beginning to end)
categoryAxis.zoom({
start: 0,
end: itemsWithNonZero / categoryAxis.dataItems.length
});
}
// Resort the series based on new data in descending order
categoryAxis.sortBySeries = series;
// Kintone REST API Request
// kintone.api(pathOrUrl, method, params, opt_callback, opt_errback)
// pathOrUrl = kintone.api.url('/k/v1/records', true);
var body = {
'app': kintone.app.getId(),
'query': kintone.app.getQueryCondition() + 'limit 500'
};
var allData = {};
// Array [Array] based on year, Manufacturer: value
// On slide - Algorithm to generate this output
// Default Field Codes: Year = Number; Manufacturer = Drop_down; PhonesSold = Number_0
kintone.api(kintone.api.url('/k/v1/records', true), 'GET', body,
function (resp) {
// Successful API Call
var records = resp.records;
records.forEach(function (record) {
if (allData.hasOwnProperty(record.Number.value)) {
allData[record.Number.value].push({
Manufacturer: record.Drop_down.value,
value: record.Number_0.value
});
return;
}
allData[record.Number.value] = [{
Manufacturer: record.Drop_down.value,
value: record.Number_0.value
}];
console.log(allData);
});
chart.data = JSON.parse(JSON.stringify(allData[year]));
categoryAxis.zoom({
start: 0,
end: 1 / chart.data.length
});
},
function (error) {
// Error
console.log(error);
});
// Register the auto play function
series.events.on('inited', function () {
play();
});
});
})();

Thank you for attending our workshop!

Your Feedback Please 🙇

Please fill out this quick survey for a chance to win 💰️ $100 Amazon Gift Card:

Next Step

For those wanting more visualization projects:

  • Try linking to different amChart libraries, and reuse the code we used in the workshop!

For those wanting to create projects on Kintone and want to retrieve & store data from public APIs:

For those wanting to use Kintone as a back-end database:

Where to Get Help?

(function () {
'use strict';
var url = "https://xkcd.com/327/info.0.json";
kintone.events.on('app.record.index.show', function (event) {
kintone.proxy(url, 'GET', {}, {}, function (success) {
var jsonResponse = JSON.parse(success);
console.log(jsonResponse);
window.open(jsonResponse.img, "", "width=800, height=200, top=200");
}, function (error) {
console.log(error);
});
return event;
});
})();

amCharts & Kintone References

Following are documentations refereed when creating the Bar Chart Race x Kintone customizations.

Kintone Events

Kintone REST API


amCharts Getting Started Tutorials

amCharts Animation

am4charts.XYChart

am4core.Label

am4charts.CategoryAxis

am4charts.ValueAxis

am4charts.ColumnSeries

am4charts.LabelBullet

amCharts Coloring

amCharts Data

amCharts Bar Chart Race

amCharts Extra Configurations

Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment