Home forums Using CanvasJS Tooltip formatting

Tagged: ,

This topic contains 4 replies, has 2 voices, and was last updated by  Indranil Deo 3 months, 1 week ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #19853

    papito
    Member

    Aside from this https://canvasjs.com/docs/charts/chart-options/tooltip/content-formatter/

    Is there an easier way to format the tooltip by passing a function like the one below so that the values gets formatted? Much like using the xValueFormatString but passing the function name instead.

    function getReadableHashRateString(hashrate){
    	hashrate = (hashrate * 2);
    	if (hashrate < 1000000) {
    		return (Math.round(hashrate / 1000) / 1000 ).toFixed(2)+' Sol/s';
    	}
        var byteUnits = [ ' Sol/s', ' KSol/s', ' MSol/s', ' GSol/s', ' TSol/s', ' PSol/s' ];
        var i = Math.floor((Math.log(hashrate/1000) / Math.log(1000)) - 1);
        hashrate = (hashrate/1000) / Math.pow(1000, i + 1);
        return hashrate.toFixed(2) + byteUnits[i];
    }
    #19856

    Indranil Deo
    Member

    @papito,

    Just like formatting the axis labels using labelFormatter as shown in this example, you can also format toolTip content using contentFormatter according to your requirements. Please take a look at this jsfiddle.

    ___________
    Indranil Deo,
    Team CanvasJS

    #19882

    papito
    Member

    But the format applies to all line series. I have two data that needs to be formatted separately.

    Sample jsfiddle https://jsfiddle.net/spakdhku/9/

    #19884

    papito
    Member

    It also doesnt work when you use shared: true on toolTip

    Edit: Looks like I was wrong, I guess you could loop through the entries?

    • This reply was modified 3 months, 1 week ago by  papito.
    #19893

    Indranil Deo
    Member

    @papito,

    Yes, you can loop through entries to get all dataPoints.

    ___________
    Indranil Deo,
    Team CanvasJS

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.