score:1

is it possible to make highchart show a dynamic data base clicked button?

Yes you can do, before to set actual data you need to set first blank data in series then set actual data.

DEMO

var assets = [{
        name: "food",
        type: [{
            name: "a",
            y: 129.2
        }, {
            name: "b",
            y: 132
        }]
    }, {
        name: "drink",
        type: [{
            name: "drink1",
            y: 512,
        }, {
            name: "drink2",
            y: 412,
        }]
    }],
    colors = ['#76daff', '#b9f', '#99ffa6', '#ffc312'];


$('button').on('click', function() {
    var attr = $(this).attr('title'),
        obj = assets.find(({name}) => name === attr);
        
    chart.series[0].setData([], true);
    chart.series[0].setData(obj.type || [], true);
});

var chart = Highcharts.chart('highchart', {
    chart: {
        type: 'bar',
        backgroundColor: null,
        height: 270,
    },
    title: {
        text: ''
    },
    xAxis: {
        type: 'category',
        labels: {
            useHTML: true,
            formatter: function() {
                return '<div class="myToolTip" style="color:' + colors[this.pos % colors.length] + '">' + this.value + '</div>';
            }
        }
    },
    colors: colors,
    yAxis: {
        min: 0,
        gridLineWidth: 0,
        title: {
            text: ''
        },
        gridLineWidth: 0,
        labels: {
            enabled: false
        }
    },
    credits: {
        enabled: false
    },
    legend: {
        enabled: false
    },
    plotOptions: {
        series: {
            dataLabels: {
                enabled: true,
                crop: false,
                overflow: 'none',
                format: '<span style="color:{point.color}">{y}</span>'
            },
            colorByPoint: true
        }
    },
    tooltip: {},
    series: [{}]
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>

<div id="highchart"></div>

<button title="food">show food</button>
<button title="drink">show drink</button>


Related Query

More Query from same tag