2016-05-27 11 views
1

私は列ハイチャートを使用しています。データの後ろに%記号が必要です。私がデータ値7.18を持っていれば、私はそれを7.18%の形式で表示したいと思っています。これどうやってするの?もし誰かが何らかのアイディアを持っていれば、私と一緒に分けてくださいハイチャートに列内にデータを含むパーセントシンボルを追加するにはどうすればよいですか?

enter image description here

私のコードは以下の通りです:

 $('#cagr2').highcharts({ 
     chart: { 
      type: 'column', 
      spacingBottom: -7, 
      spacingTop:20 
     }, 
     title: { 
      text: '' 
     }, exporting: { enabled: false }, 
     credits: { 
     enabled: false 
     }, 
     xAxis: { 
      lineColor: 'transparent', 
      categories: [''] 
     }, 
     yAxis: { 

    lineWidth: 0, 
    minorGridLineWidth: 0, 
    minorGridLineWidth: 0, 
    gridLineColor: 'transparent', 
    lineColor: 'transparent', 

    labels: { 
     enabled: false 
    }, 
    minorTickLength: 0, 
    tickLength: 0, 
       min: 0, 
      title: { 
       text: '' 
      }, 
      stackLabels: { 
       enabled: false, 
       style: { 
        fontWeight: 'bold', 
        color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray' 
       } 
      } 
     }, 

     legend: { 
      enabled: true, 
      layout: 'horizontal', 
      align: 'center', 
      //x: -10, 
      verticalAlign: 'top', 
      y: -5, 
      floating: true, 
      backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white', 
      borderColor: '#ffffff', 
      borderWidth: 1, 
      shadow: true 
     }, 
     tooltip: { 
      headerFormat: '<b>{point.x}</b>', 
      pointFormat: '{series.name}: {point.y}', 
      valueSuffix: ' %' 
     }, 

     plotOptions: { 
      series: { 

       animation: { 
        duration: 7000 
       } 

      }, 

      column: { 
       stacking: 'normal', 
       dataLabels: { 
        enabled: true, 
        color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white', 
        style: { 
         textShadow: '0 0 3px black', 
         fontSize: '18px' 
        } 
       } 
      } 
     }, 
     series: [{ 
      name: 'Rate of return', 
      data: [parseFloat(cagr)] 
     }] 
    }); 

答えて

2

あなたがここにする必要があるすべてはあなたのdataLabelsformatまたはformatter属性を追加しています。

formatを使用した例:formatterを使用して

column: { 
    stacking: 'normal', 
    dataLabels: { 
     enabled: true, 
     color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white', 
     style: { 
      textShadow: '0 0 3px black', 
      fontSize: '18px' 
     }, 
     format: '{y} %', // your label's value plus the percentage sign 
     valueDecimals: 2 // show your label's value up to two decimal places 
    } 
} 

例:

column: { 
    stacking: 'normal', 
    dataLabels: { 
     enabled: true, 
     color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white', 
     style: { 
      textShadow: '0 0 3px black', 
      fontSize: '18px' 
     }, 
     formatter: function() { 
      // numberFormat takes your label's value and the decimal places to show 
      return Highcharts.numberFormat(this.y, 2) + '%'; 
     }, 
    } 
} 

ここでは、これがどのように見えるかです:

enter image description here

こちらがお役に立てば幸いです。

+1

ありがとうございます、そのうまく動作します。 –

関連する問題