data label is not shown Highcharts

↘锁芯ラ 提交于 2019-12-23 10:09:27

问题


I'm trying to show datalabels. but DATALABEL the black bar is not shown. why?

http://jsfiddle.net/o4pt855e/

other bars are displayed well. I take this opportunity to ask how I can put a condition ?. if the value is less than 5, the DATALABEL be shown to the left, otherwise the right.

$(function () {
 $('#container').highcharts({
        chart: {
            type: 'bar'
        },
        title: {
            text: 'Mi EPS'
        },
        xAxis: {
            //categories: ["number1", "number2", "number3", "number4","number5"],
            title: {
                text: null
            },
            labels: {

             // align: 'center',
              x: -5,
              y: -20,
              useHTML: true,
              format: '<div style="position: absolute; left: 40px"> my labelL is very large ***************************************this in other line! </div> <img style="height: 30px; width: 30px; margin-top: 10px"  src="https://cdn2.iconfinder.com/data/icons/free-3d-printer-icon-set/512/Plastic_model.png"></img>'

            }

        },
        yAxis: {

            title: {
                text: 'Resultado',
                 align: 'right'
            }

        },
        tooltip: {
            valueSuffix: ' dollars'
        },
        plotOptions: {
            bar: {
                dataLabels: {
                    enabled: true,
                    align: 'left',
                    color: '#FFFFFF',
                    inside: true,
                    crop: false,
                    overflow:"none",
                        formatter: function() {

                    return this.series.name+ " "+ this.y;

                    console.log(this.series.name);
                },
                    style:{
                        width:100
                    }

                }
            }
        },
        legend: {
            layout: 'vertical',
            align: 'center',
            verticalAlign: 'bottom',
            x: -40,
            y:40 ,
            floating: true,
            borderWidth: 1,
            backgroundColor: '#FFFFFF',
            shadow: true
        },
        credits: {
            enabled: false
        },
         series: [{
          name: 'Mejor Eps',
          data: [1000, 950,920,880,850],
          color: "#FF0000"
      }, {
          name: 'Mi Eps',
          data: [800,770,750,740,730],
          color: "#000000"

      }, {
          name: 'Peor Eps',
          data: [600,540,535,500,0],
          color: "#00FF00"

      }]
    });
});

回答1:


Defaulty each datalabel has a padding and when overlaps other label then is hidden. So you need to set padding as 0 and allowOverlap option as true.

plotOptions: {
            bar: {
                dataLabels: {
                padding:0,
                allowOverlap:true,
                    enabled: true,
                    align: 'left',
                    color: '#FFFFFF',
                    inside: true,
                    crop: false,
                    overflow:"none",
                        formatter: function() {

                    return this.series.name+ " "+ this.y;

                    console.log(this.series.name);
                },
                    style:{
                        width:100
                    }

                }
            }
        },

http://jsfiddle.net/vj19ukbc/



来源:https://stackoverflow.com/questions/34755251/data-label-is-not-shown-highcharts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!