Search code examples
javascripthtmlcanvasjs

how to input chart into value format, not percent format


<!DOCTYPE HTML>
<html>
<head>
<script>
window.onload = function() {

var chart = new CanvasJS.Chart("chartContainer", {
    animationEnabled: true,
    title: {
        text: "Desktop Search Engine Market Share - 2016"
    },
    data: [{
        type: "pie",
        startAngle: 240,
        yValueFormatString: "##0.00\"%\"",
        indexLabel: "{label} {y}",
        dataPoints: [
            {y: 79.45, label: "Google"},
            {y: 7.31, label: "Bing"},
            {y: 7.06, label: "Baidu"},
            {y: 4.91, label: "Yahoo"},
            {y: 1.26, label: "Others"}
        ]
    }]
});
chart.render();

}
</script>
</head>
<body>
<div id="chartContainer" style="height: 300px; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</body>
</html>

so i have this syntax, but when appear, it become percent for the value, how to transform the format become the values itself, not percent format (%)


Solution

  • You can format the y-value being shown in toolTip by setting yValueFormatString. Removing yValueFormatString from the code should should according to your requirements.

    var chart = new CanvasJS.Chart("chartContainer", {
      title: {
          text: "Desktop Search Engine Market Share - 2016"
      },
      data: [{
          type: "pie",
          startAngle: 240,
          //yValueFormatString: "##0.00\"%\"",
          indexLabel: "{label} {y}",
          dataPoints: [
              {y: 79.45, label: "Google"},
              {y: 7.31, label: "Bing"},
              {y: 7.06, label: "Baidu"},
              {y: 4.91, label: "Yahoo"},
              {y: 1.26, label: "Others"}
          ]
      }]
    });
    chart.render();
    <script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
    <div id="chartContainer" style="height: 200px; width: 100%;"></div>