3

I have created a chart using Highcharts, which drilldown in the second click to show more information. In the first click, I can also select multiple charts using Shift+click or Ctrl+click. I also implemented a little div which appears when the user select one or more column and displays some information.

My trouble is: I want to implement this chart to iPad or any other portable device, so the user won't have shift or ctrl key. I want to create a multiple selection where first click selects as any chars the user click (and also unselect when clicks again) and the second click displays a drilldown, all keeping the structure I have. I know that is a fetched question but I will appreciate any help.

HTML code:

<html>
    <head>
        <title>Highcharts</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <script src="https://code.highcharts.com/highcharts.js"></script>
        <script src="https://code.highcharts.com/modules/data.js"></script>
        <script src="http://github.highcharts.com/modules/exporting.js"></script>
        <script src="https://code.highcharts.com/modules/drilldown.js"></script>
        <script src="highcharts.js" type="text/javascript"></script>
        <!--Black theme
        <script src="black-theme.js" type="text/javascript"></script>
        -->
    </head>
    <body>
        <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>       
    </body>
</html>

Javascript code:

$(function () {
    // Create the chart
    $('#container').highcharts({
        chart: {
            type: 'column',
            events: {
                drilldown: function (e) {
                    if (!e.seriesOptions && e.point.selected) {
                        var chart = this,
                                points = chart.getSelectedPoints(),
                                drilldowns = {
                                    'Animals': {
                                        name: 'Animals',
                                        data: [
                                            ['Cows', 2],
                                            ['Sheep', 3]
                                        ]
                                    },
                                    'Fruits': {
                                        name: 'Fruits',
                                        data: [
                                            ['Apples', 5],
                                            ['Oranges', 7],
                                            ['Bananas', 2]
                                        ]
                                    },
                                    'Cars': {
                                        name: 'Cars',
                                        data: [
                                            ['Toyota', 1],
                                            ['Volkswagen', 2],
                                            ['Opel', 5]
                                        ]
                                    }
                                };

                        Highcharts.each(points, function (p) {
                            chart.addSingleSeriesAsDrilldown(p, drilldowns[p.name]);
                        });
                        chart.applyDrilldown();
                    }

                },
                drillup: function (e) {
                    var chart = this,
                            points = [];
                    setTimeout(function () {
                        points = chart.getSelectedPoints();

                        Highcharts.each(points, function (p) {
                            // unselect points from previous drilldown
                            p.selected = false;
                            p.setState('', true);
                        });
                    }, 0);
                }
            }
        },
        title: {
            text: 'Async drilldown'
        },
        xAxis: {
            type: 'category',
            categories: []
        },
        yAxis: {
            title: {
                text: 'Values'
            }

        },
        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}</b></td></tr>',
            footerFormat: '</table>',
            shared: false,
            useHTML: true
        },
        legend: {
            enabled: false
        },
        plotOptions: {
            column: {
                allowPointSelect: true
            },
            series: {
                borderWidth: 0,
                dataLabels: {
                    enabled: true
                },
                point: {
                    events: {
                        select: function (event) {
                            var text = 'All selected points: <br/>',
                                    chart = this.series.chart,
                                    otherSelected = chart.getSelectedPoints();
                            if (event.accumulate) {
                                Highcharts.each(otherSelected, function (point) {
                                    text += point.name + ', value: ' + point.y + '<br/>';
                                });
                            }
                            var pretext = this.name + ', value: ' + this.y + ' (last selected)';
                            text += pretext.bold();
                            if (!chart.lbl) {
                                chart.lbl = chart.renderer.label(text, 100, 70)
                                        .attr({
                                            padding: 10,
                                            r: 5,
                                            fill: Highcharts.getOptions().colors[1],
                                            zIndex: 5
                                        })
                                        .css({
                                            color: '#FFFFFF'
                                        })
                                        .add();
                            } else {
                                chart.lbl.attr({
                                    text: text
                                });
                            }
                        }
                    }
                }
            }
        },
        series: [{
                allowPointSelect: true,
                name: 'Test things',
                colorByPoint: true,
                data: [{
                        name: 'Animals',
                        y: 2,
                        drilldown: true
                    }, {
                        name: 'Fruits',
                        y: 7,
                        drilldown: true
                    }, {
                        name: 'Cars',
                        y: 4,
                        drilldown: true
                    }]
            }],
        drilldown: {
            series: []
        }
    })
});

Jsfiddle: http://jsfiddle.net/ah7gzxth/

EDIT: I would like to implement the following jsfiddle in my chart, but I'm not able to achieve that goal. http://jsfiddle.net/3zy8p/58/

Summary:

I want to perform a multiple selection (similar than allowPointSelect:true) without using Shift+click/Ctrol+click in the first chart as well as in drilldowns implemented in my code.

Thanks to everyone!

Ferran Buireu
  • 28,630
  • 6
  • 39
  • 67
  • Hmm.. but how exactly should that work? Maybe you want to implement some kind of a checkbox for mobile devices which can be checked to select multiple points? Then instead of `select` use `click` event, where you can call `point.select(true, true)`? – Paweł Fus Dec 04 '15 at 12:14
  • It should work as well as in PC and portable devices. I have also tried what you said, it works in a normal charts, but in my case, I have a drilldown. So, the first click should perform the selection and the second the drilldown. The code that I have already accomplish that perfectly, but the only way I have to select is using Cntrol+click/Shift+click, and I want to avoid that to make my chart usable for portable devices. I'm looking another way to select (similar than you explained) but letting me use the drilldown. Hope I've explained my issue better. Thanks for answering – Ferran Buireu Dec 04 '15 at 14:45
  • 1
    @FerranBuireu Maybe you could use a button that will perform a drilldown? That way clicking is for select/unselect and the button for drilldown. – Kacper Madej Dec 07 '15 at 16:32
  • That's another intereting point of view. I'm a bit afraid because I am not good enough to reach this I think but I will try – Ferran Buireu Dec 07 '15 at 19:56
  • 1
    http://jsfiddle.net/3zy8p/58/ this example save my time. appreciate!!! – ryh Sep 01 '22 at 05:05

0 Answers0