简体   繁体   English

Highcharts 柱形图,带目标和颜色渐变

[英]Highcharts column chart with target and color gradient

Is below chart possible in highchart是否可以在高图中低于图表

  1. Column with high, low and target具有高、低和目标的列
  2. Color gradient with denser on target and lighter away颜色渐变,在目标上更密集,在远处更亮
  3. Data table for low, high and target低、高、目标数据表

Managed to get some bits, but not full functionality设法得到一些位,但不是完整的功能

https://jsfiddle.net/z9u5hgod/2/ https://jsfiddle.net/z9u5hgod/2/

TIA TIA

海图

[
  
  {
   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
    }]
  }]

Response from higcharts developer来自 higcharts 开发者的回应

https://jsfiddle.net/BlackLabel/xbvp8he7/ 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})'
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM