2016-02-26 39 views
1

我有一个网站,这使得使用HighCharts固体计Highcharts - 固体计 - 不一致的造型和不正确的价值观

有计两行。

计的第一行如下构建。

var workgroups =['WG01','WG02','WG04', 
     'WG05','WG06','All']; 

$(function() 
{ 
    var gaugeOptions = { 
     chart: { 
      type: 'solidgauge' 
     }, 
     title: 'Gauge', 

     pane: { 
      // Positioning 
      center: ['50%', '60%'], 
      // img size 
      size: '100%', 
      // full circle/half circle 
      startAngle: -90, 
      endAngle: 90, 
      // gauge coloring 
      background: { 
       backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || '#000', 
       // Inner semi circle sizing 
       innerRadius: '60%', 
       outerRadius: '100%', 
       shape: 'arc' 
      } 
     }, 

     tooltip: { 
      enabled: false 
     }, 

     // the value axis 
     yAxis: { 
      stops: [ 
       // Set the limits for coloring 
       [0.1, '#55BF3B'], // green 
       [0.4, '#DDDF0D'], // yellow 
       [0.9, '#DF5353'] // red 
      ], 
      // Outside Line buffer 
      lineWidth: 0, 
      minorTickInterval: null, 
      tickPixelInterval: 400, 
      tickWidth: 0, 
      title: { 
       // Title Location 
       y: -30 
      }, 
      labels: { 
       style:{ 
        color: "#000000", 
        fontSize: "13px" 
       }, 
       // Bottom Label Offset 
       y: 15, 
       distance: -10, 
      } 
     }, 

     plotOptions: { 
      solidgauge: { 
       dataLabels: { 
        style:{ 
         color: "000000", 
         fontSize: "15px" 
        }, 
        borderWidth: 0, 
        useHTML: true 
       } 
      } 
     } 
    }; 
    // The gauges 

    for(i in workgroups){ 
     if(workgroups[i] == 'All'){ 
      header = "All"; 
      gaugeOptions.yAxis['stops'] = [[.5, '#000000']] 
     }else{ 
      header = "WG" + workgroups[i].slice(-2); 
     } 
     $('#'+workgroups[i]).highcharts(Highcharts.merge(gaugeOptions, { 

      yAxis: { 
      min: 0, 
      max: 100, 
       title: { 
        style:{ 
         color: "#000000", 
         fontWeight: 'bold', 
         fontSize: '22px' 
        }, 
        text: header 
       } 
      }, 
      credits: { 
       enabled: false 
      }, 
      series: [{ 
       name: workgroups[i], 
       data: [0], 
       dataLabels: { 
        y: 40, 
        format: '<div style="text-align:center"><span style="font-size:25px;color:' + 
         ((Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black') + '">{y}</span><br/>' + 
         '<span style="font-size:12px;color:silver">clients</span></div>' 
       }, 
      }] 
     })); 
    } 
} 
); 

并得到如下图像。

enter image description here

,这是好的,正确的价值观,所有的风格适合在那里他们应该。

做这些规之后,我们做仪表的第二排。 (当前)配置这些计是:

var application_array = new Array(3); 
application_array['Sapphire'] = 50; 
application_array['Magic Bullet'] = 35; 
application_array['Boris'] = 30; 

$(function() 
{ 
    var gaugeOptions = { 
     chart: { 
      type: 'solidgauge' 
     }, 
     title: 'Gauge', 

     pane: { 
      // Positioning 
      center: ['50%', '85%'], 
      // img size 
      size: '150%', 
      // full circle/half circle 
      startAngle: -90, 
      endAngle: 90, 
      // gauge coloring 
      background: { 
       backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || '#000', 
       // Inner semi circle sizing 
       innerRadius: '60%', 
       outerRadius: '100%', 
       shape: 'arc' 
      } 
     }, 

     tooltip: { 
      enabled: false 
     }, 

     // the value axis 
     yAxis: { 
      stops: [ 
       // Set the limits for coloring 
       [0.1, '#55BF3B'], // green 
       [0.4, '#DDDF0D'], // yellow 
       [0.9, '#DF5353'] // red 
      ], 
      // Outside Line buffer 
      lineWidth: 0, 
      minorTickInterval: null, 
      tickPixelInterval: 400, 
      tickWidth: 0, 
      title: { 
       // Title Location 
       y: -30 
      }, 
      labels:{ 
       y:13 
      } 

     }, 


    }; 
    // Build the gauges here 
    var license_gauges = document.getElementsByClassName('gaugeCell2'); 
    var myLength = license_gauges.length; 
    for (i=0; i <myLength; i++){ 

     var header = license_gauges[i].id; 
     var selector = "[id='"+header+"']"; 
     if (header == 'Boris'){ 
      var max_value = 30; 
     }else if (header == 'Magic Bullet'){ 
      var max_value = 35; 
     }else if (header == 'Sapphire'){ 
      var max_value = 50; 
     } 
     console.log(header) 
     $(selector).highcharts(Highcharts.merge(gaugeOptions, { 


      yAxis: { 
      min: 0, 
      max: max_value, 
       title: { 
        style:{ 
         color: "#000000", 
         fontWeight: 'bold', 
         fontSize: '22px' 
        }, 
        text: header 
       } 
      }, 
      credits: { 
       enabled: false 
      }, 
      series: [{ 
       name: header, 
       data: [0], 

      }] 
     })); 
    } 

}); 

产生以下BAD仪表 enter image description here

我的问题

1)在计的第二行,为什么是否打印25为max第二和第三量规? - 我曾尝试相联系的数组,以保持适当的值时,发生同样的问题

  • 我曾尝试时,发生同样的问题
  • 我已在规创作本身试图逻辑,它返回一个静态值的函数,同样的问题出现
  • 我试图写一个静态值作为最大和所有仪表得到适当的值

2)在第二行规的,这是为什么认为max值,对于第二和第三压力表是不一致格式化与所述第一计?

  • 我已经尝试过几乎所有我能想到的布局配置,但它仍然保持相同的问题。

  • 当使用静态最大值时,不会发生此问题。 enter image description here

  • 我是否需要为每个量表制定单独的测量选项,因为它们具有不同的最大值?我想在顶行中使用1号规格样式,在底行中使用1号规格样式(较胖)。

在这里创建了一个JSFiddle。最有可能的是无关代码(特别是css),因为我想快速启动并运行它。

http://jsfiddle.net/v341z7tk/1/

感谢您阅读

回答

1

为什么打印25为max的第二和第三计?

不是。也就是说,最大值不是25,但绘制的轴标签显示值25,因为在该值处有一个轴刻度。最大值不显示标签。

为什么第二个和第三个量表的max值与第一个量表不一致?

位置不一致,因为25标签位于不同的位置,具体取决于最大值。在你的情况下,最后两个量表是35和30。

我是否需要为每个量表制定单独的测量选项,因为它们具有不同的最大值?

号从我的理解,你想在启动(0)和结束(max_value)的标签。为了得到这个,你需要确保坐标轴(有相关的标签)在这些位置,只有这些。

一个简单的方法是这样的(JSFiddle):

yAxis: { 
    min: 0, 
    max: max_value, 
    tickPositions: [0, max_value], // Ensure position of ticks, which have labels 
    // ... 
} 
0

我有同样的问题,但下面有什么Halvor斯特朗说解决我的问题,像这样

displayOptions.yAxis.min = widget.display.minimum; 
displayOptions.yAxis.max = widget.display.maximum; 
displayOptions.yAxis.tickPositions = [widget.display.minimum, widget.display.maximum]; 

distorted labels - Minimum and maximum out of place