具有目标和颜色渐变的Highcharts柱形图

1l5u6lss  于 2022-11-10  发布在  Highcharts
关注(0)|答案(1)|浏览(268)

在 highcharts 中是否可能低于图表
1.具有高值、低值和目标值的列
1.颜色渐变,目标上颜色较浓,远处颜色较淡
1.低、高和目标值数据表
设法获得了一些信息,但未获得全部功能
https://jsfiddle.net/z9u5hgod/2/
短暂性脑缺血

[

  {
   type: 'bullet',
   dataLabels: [
   { format: '{point.y}' } ,

   {format: '{point.target}',
        inside: true},

   {
    inside: true,
    verticalAlign: 'bottom',
    align: 'center',
    format: '{point.low}'
   }
   ],
    data: [
    {
      low: 250,
      y: 1650,
      target: 750,
      color: {
        linearGradient: [0, '70%', 0, '50%'],
          stops: [
            [0, 'green'],
            [1, 'orange']
          ]
      }
    }, 
    {
      low: 100,
      y: 2000,
      target: 1500
    }
    ]
  }, 

  {
    data: [{
     low: 600,
      y: 2350,
      target: 2100
    }, {
     low: 450,
      y: 1700,
      target: 1250
    }]
  }]
py49o6xq

py49o6xq1#

higcharts开发人员的回应
https://jsfiddle.net/BlackLabel/xbvp8he7/

const chart = Highcharts.chart('container', {
  chart: {
    type: 'bullet',
    events: {
      load() {
        const firstSeries = this.series[0];

        firstSeries.data.forEach(point => {
          const {
            low,
            y,
            target
          } = point,
          gradientPoint = (y - target) / (y - low);

          point.update({
            color: {
              linearGradient: {
                x1: 0,
                x2: 0,
                y1: 0,
                y2: 1
              },
              stops: [
                [0, 'blue'],
                [gradientPoint, 'purple'],
                [1, 'blue']
              ],
            }
          })
        })
      }
    }
  },
  plotOptions: {
    series: {
      pointPadding: 0.2,
      groupPadding: 0.1,
      targetOptions: {
        borderWidth: 0,
        height: 3,
        color: 'red',
        width: '100%'
      }
    }
  },
  xAxis: {
    categories: ['Alex ar', 'Cairo ar']
  },
  series: [

    {
      type: 'bullet',
      dataLabels: [{
        enabled: true,
      }, {
        enabled: true,
        verticalAlign: 'top',
        align: 'center',
                color: 'white',
        useHTML: true,
        formatter() {
          const point = this.point,
            target = point.targetGraphic,
            targetY = target.getBBox().y - point.shapeArgs.y - 25;

          return `
                        <div class="datalabelInside" style="position: relative; top: ${targetY}px">${point.target}</div>
                    `;

        }
      }, {
        verticalAlign: 'bottom',
        inside: true,
        y: 20,
        format: '{point.low}',
        enabled: true
      }, ],
      data: [{
          low: 250,
          y: 1650,
          target: 750
        },
        {
          low: 100,
          y: 2000,
          target: 1500
        }
      ]
    },

    {
      data: [{
        low: 600,
        y: 2350,
        target: 2100
      }, {
        low: 450,
        y: 1700,
        target: 1250
      }]
    }
  ],
  tooltip: {
    pointFormat: '<b>{point.y}</b> (with target at {point.target})'
  }
});

相关问题