As for two values in highcharts

Asked

Viewed 340 times

1

I set up a chart with highcharts where I need to know the percentage of financial input and output.

<div id="container" style="min-width: 410px; height: 500px; max-width: 600px; margin: 0 auto; margin-top: 25px"></div>

<script>
  Highcharts.chart('container', {
    chart: {
      plotBackgroundColor: null,
      plotBorderWidth: null,
      plotShadow: false,
      type: 'pie'
    },
    title: {
      text: 'Gastos Periodo - <?php echo $periodoEntrada . ' - ' . $periodoSaida?>'
    },
    tooltip: {
      pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
    },
    plotOptions: {
      pie: {
        allowPointSelect: true,
        cursor: 'pointer',
        dataLabels: {
          enabled: true,
          format: '<b>{point.name}</b>: {point.percentage:.1f} %',
          style: {
            color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
          }
        }
      }
    },
    series: [{
      colorByPoint: true,
      data: [{
        name: 'Entradas',
        y: <?php echo str_replace(",", ".", $entrada);?>,
      }, {
        name: 'Saidas',
        y: <?php echo str_replace(",", ".", $saida);?>,
      }]
    }]
  });
</script>

inserir a descrição da imagem aqui

How Do I Get Where Series Is

Entrada 
 - Porcentagem - 93% 
 - Valor - 500,00
  • Pq 93%? This number is not automatic?

  • Something like that: pointFormat: 'Porcentagem - <b>{point.percentage:.1f}%</b> <br> Valor - <?php echo $variavelDoValor ?>'?

  • Try: pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b><br>Valor: <b>{point.y:.2f}</b>'

1 answer

1


Use point.y which is the value of the slice:

pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b><br>Valor - <b>{point.y:.2f}</b>'

The .2f will display two decimal places. To put the comma as the decimal separator and the thousand point, use:

Highcharts.setOptions({
    lang: {
        decimalPoint: ',',
        thousandsSep: '.'
    }
});

Example:

Highcharts.setOptions({
    lang: {
        decimalPoint: ',',
        thousandsSep: '.'
    }
});

Highcharts.chart('container', {
                        chart: {
                            plotBackgroundColor: null,
                            plotBorderWidth: null,
                            plotShadow: false,
                            type: 'pie'
                        },
                        title: {
                            text: 'Gastos Periodo - x - y'
                        },
                        tooltip: {
                            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b><br>Valor: <b>{point.y:.2f}</b>'
                        },
                        plotOptions: {
                            pie: {
                                allowPointSelect: true,
                                cursor: 'pointer',
                                dataLabels: {
                                    enabled: true,
                                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                                    style: {
                                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                                    }
                                }
                            }
                        },
                        series: [{
                            colorByPoint: true,
                            data: [{
                                name: 'Entradas',
                                y: 500,
                            }, {
                                name: 'Saidas',
                                y: 50,
                            }]
                        }]
                    });
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container" style="min-width: 410px; height: 500px; max-width: 600px; margin: 0 auto; margin-top: 25px"></div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.