JSFiddle - React, Tailwind, and code Playground

by klsakthi

HTML

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>

<button style="margin: 10px;" id="addSeaPressure">
Add Sea Level Pressure
</button>
<button style="margin: 10px;" disabled="disabled" id="removeSeaPressure">
Remove Sev Level Pressure
</button>
<button style="margin: 10px;" id="addRainfall">
Add Rainfall
</button>
<button style="margin: 10px;" disabled="disabled" id="removeRainfall">
Remove Rainfall
</button>

JavaScript

// the button handlera
$('#addSeaPressure').click(function () {
    window.chart.addAxis({ // Secondary yAxis
				id:'sealevel-yaxis',
        gridLineWidth: 0,
        title: {
            text: 'Sea-Level Pressure',
            style: {
                color: '#7cb5ec'
            }
        },
        labels: {
            format: '{value} mb',
            style: {
                color: '#7cb5ec'
            }
        },
        opposite: true,
        lineColor: '#7cb5ec',
        lineWidth: 1
    });
    window.chart.addSeries({
        name: 'Sea-Level Pressure',
        id: 'sealevel',
        type: 'spline',
        data: [1016, 1016, 1015.9, 1015.5, 1012.3, 1009.5, 1009.6, 1010.2, 1013.1, 1016.9, 1018.2, 1016.7],
        marker: {
            enabled: false
        },
        dashStyle: 'shortdot',
        yAxis: 'sealevel-yaxis',
        tooltip: {
            valueSuffix: ' mb'
        }
    });
    $(this).attr('disabled', true);
    $('#removeSeaPressure').attr('disabled', false);
});
$('#removeSeaPressure').click(function () {
    window.chart.get('sealevel-yaxis').remove();

    $(this).attr('disabled', true);
    $('#addSeaPressure').attr('disabled', false);
});


$('#addRainfall').click(function () {
    window.chart.addAxis({ // Secondary yAxis
    		id:'rainfall-yaxis',
				gridLineWidth: 0,
        title: {
            text: 'Rainfall',
            style: {
                color: '#7cb5ec'
            }
        },
        labels: {
            format: '{value} mm',
            style: {
                color: '#7cb5ec'
            }
        },
        lineColor: '#7cb5ec',
        lineWidth: 1
    });
    window.chart.addSeries({
        name: 'Rainfall',
        id: 'rainfall',
        type: 'column',
        yAxis: 'rainfall-yaxis',
        data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
        tooltip: {
            valueSuffix: ' mm'
        }
    });
    $(this).attr('disabled', true);
   ...