1

I want to inline edit x-xaxis/y-axis title on click of it. I read about custom-events plugin of highcharts. It gave me click event on axis title but how can I inline edit it and then update the axis title of chart on enter button click.

check this fiddle - https://jsfiddle.net/Utx8g/901/

$(function () {
var lastUpdate = +new Date(),
    timeout = 3000;

function reloadFlash() {
    $("#flash").fadeIn();
    lastUpdate = +new Date();
    setTimeout(hideFlash, timeout);
}

function hideFlash() {
    var now = +new Date();
    if (now >= lastUpdate + timeout) {
        $("#flash").fadeOut();
    }
}

$('#chart').highcharts({
    chart: {
        renderTo: 'chart',
        borderRadius: 0,
        marginTop: 70,
        events: {
            load: function () {
                //add report div
                var ch = this,
                    x = 20,
                    y = 57;

                ch.flashText = ch.renderer.text('<div id="flash"><div id="report"></div></div>', x , y +10, true).attr({
                    zIndex: 101
                }).add();
            }
        }
    },
    title: {
        useHTML: true,
        align: 'left',
        x: -5,
        y: 8,
        text: '<span class="chart-title"> Custom events  <span class="chart-href"> <a href="http://www.blacklabel.pl/highcharts" target="_blank"> Black Label </a> </span> <span class="chart-subtitle">plugin by </span></span>'

    },
    yAxis: [{
        title: {
            text: 'Values',
            events: {
                dblclick: function () {
                    reloadFlash();
                    $('#report').html('dbclick on yAxis title');
                },
                click: function () {
                    reloadFlash();
                    $('#report').html('click on yAxis title');
                },
                contextmenu: function () {
                    reloadFlash();
                    $('#report').html('context menu on yAxis title');
                }
            }
        },
        plotLines: [{
            value: 70

        }],
        plotBands: [{ // mark the weekend
            from: 100,
            to: 200

        }],
        labels: {

        }
    }, {
        opposite: true,
        linkedTo: 0,
        labels: {

        }
    }],
    xAxis: {
        title:{
            text: 'xAxis title',
            events: {
                dblclick: function () {
                    reloadFlash();
                    $('#report').html('dbclick on xAxis title');
                },
                click: function () {
                    reloadFlash();
                    $('#report').html('click on xAxis title');
                },
                contextmenu: function () {
                    reloadFlash();
                    $('#report').html('context menu on xAxis title');
                }
            }
        },
        labels: {
            rotation: -45

        }
    },
    plotOptions: {
        series: {
            dataLabels: {
                enabled: true,
                events: {
                    dblclick: function () {
                        reloadFlash();
                        $('#report').html('dbclick on datalabel');
                    },
                    click: function () {
                        reloadFlash();
                        $('#report').html('click on datalabel');
                    },
                    contextmenu: function () {
                        reloadFlash();
                        $('#report').html('context menu on datalabel');
                    }
                }
            },
            events: {
                dblclick: function () {
                    reloadFlash();
                    $('#report').html('dbclick on serie');
                },
                click: function () {
                    reloadFlash();
                    $('#report').html('click on serie');
                },
                contextmenu: function () {
                    reloadFlash();
                    $('#report').html('context menu on serie');
                }
            },
            point: {
                events: {
                    dblclick: function () {
                        reloadFlash();
                        $('#report').html('dbclick on serie point');
                    },
                    click: function () {
                        reloadFlash();
                        $('#report').html('click on serie point');
                    },
                    contextmenu: function () {
                        reloadFlash();
                        $('#report').html('context menu on serie point');
                    }
                }
            }
        }
    },
    legend: {

    },
    series: [{
        data: [99.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135, 43]
    }, {
        type: 'column',
        data: [50, 16, 21, 11, 22, 12]
    }]
});

});

Purva K
  • 23
  • 6
  • 1
    Yes, you can change the text of the element via this.element.attr({text: 'new text'`}) See example https://jsfiddle.net/9b8mn00e/ – morganfree Jul 19 '17 at 13:26
  • But I want to edit axis title inline over the chart by clicking on the title. Check this kendo demo about inline editing of grid - http://demos.telerik.com/kendo-ui/grid/editing-inline they have given an edit button, which enables inline editing for all the cells in that rows. I want similar effect on click of axis title, which they have given on click of edit button. – Purva K Jul 20 '17 at 05:58
  • Check this also - https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_global_contenteditable I want similar effect on click of axis title – Purva K Jul 20 '17 at 06:07
  • You can implement it in this way - on click event create a temporary input element and position it so it will cover the original y axis title. It should be styled in the same way as y axis title. On input submit/enter you should change y axis title. – morganfree Jul 20 '17 at 10:50

0 Answers0