JSFiddle - React, Tailwind, and code Playground
by fruitcake20
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<button id="delete" class="buttonFlat">
Delete Paired Textfield
</button>
<button id="add" class="buttonFlat">
Add Country
</button>
<button id="shout" class="buttonFlat">
Generate Chart
</button>
<div id="dataInput" class="data-input">
</div>
CSS
.buttonFlat {
border: none;
background-color: dimgrey;
color: white;
margin: 20px 5px 7px 0px;
}
JavaScript
$(function() {
var userData = [];
var inputData = {};
var chart;
var txtblank=0;
chart = Highcharts.chart('container', {
chart: {
type: 'column'
},
title: {
text: 'Countries and their Population'
},
subtitle: {
text: 'Source: data.worldbank.org'
},
xAxis: {
categories: ['2016'],
crosshair: true
},
yAxis: {
min: 0,
title: {
text: 'Population (million)'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: []
});
var dataInput = $('#dataInput');
$('#add').click(function() {
add_field();
});
$('#shout').click(function() {
shout_content();
});
$('#delete').click(function() {
$("#dataInput").children("div[class=row]:last").remove();
Load();
});
function add_field() {
dataInput.append('<div class="row"><input class="country" placeholder="Country"/><input class="population" type="number" placeholder="Population"/></div>');
iftxtBlnk();
}
$( document ).ready( Load );
function Load()
{
if ( $('#dataInput').children().length == 0 )
{
$("#shout").attr('disabled', true);
}
}
$(document).on('keyup', "input",function () {
iftxtBlnk();
});
function checkEmpty()
{
txtblank=0;
$("#dataInput").children(".row").each(function()
{
var inputs = $(this).children('input');
var country = inputs[0].value;
var population = parseInt(inputs[1].value);
if(country=="")
{
txtblank++;
}
if(isNaN(population))
{
txtblank++;
}
});
if(txtblank!=0)
{
return true;
...