Question

im using a common function to generate linechart using highchart.for certain charttype i want tooltip without any pointformat and for another in want to use formatter funcction how to acheive this.From the below code charttype 1 tooltip diappear.

tooltip: { valueSuffix: '', pointFormat: (chartType == 1 ? '{series.name}: {point.y}
' : '' ) , shared: (chartType == 1 ? true : false),

                formatter: function() {
                    if (chartType == 2) {
                        return '' + this.point.tooltip + ': ' + (chartType == 2 ? this.y.toFixed(1) : this.y.toFixed(0));
                    } 
                    else {
                        return false;
                    }
                }
Was it helpful?

Solution

If you want to disable option, use null value, not empty string (''). See: http://jsfiddle.net/Yrygy/133/

However I think that it would be better to add one if-else statement, instead of three one above another, see: http://jsfiddle.net/Yrygy/134/

    var chartType = 1,
        tooltip = {
            valueSuffix: ''
        };

    if (chartType == 1) {
        tooltip.pointFormat = '{series.name}: {point.y}';
        tooltip.shared = true;
    } else {
        tooltip.shared = false;
        tooltip.formatter = function () {
            if (chartType == 2) {
                return '' + this.point.tooltip + ': ' + (chartType == 2 ? this.y.toFixed(1) : this.y.toFixed(0));
            } else {
                return false;
            }
        }
    }

And then create chart:

    chart = new Highcharts.Chart({
        tooltip: tooltip,
        // other options
    });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top