2016-08-09 35 views
1

Ich habe ein Highcharts-Winkelmessgerät erstellt. Ich muss die Nadelladeanimation verzögern. HierIst es möglich, die Nadel-Lade-Animation in Highcharts-Winkelmesser zu verzögern?

ist der Code:

$(function() { 
 

 
    $('#meter').highcharts({ 
 

 
     chart: { 
 
      type: 'gauge', 
 
      plotBackgroundColor: null, 
 
      plotBackgroundImage: null, 
 
      plotBorderWidth: 0, 
 
      plotShadow: false 
 
     }, 
 
     credits: { 
 
      enabled: false 
 
     }, 
 
     title: { 
 
      text: '' 
 
     }, 
 
     // 
 
     plotOptions: { 
 
      gauge: { 
 
       dataLabels: { 
 
        enabled: false 
 
       }, 
 
       dial: { 
 
        radius: '70%', 
 
        backgroundColor: '#000', 
 
        topWidth: 1, 
 
        baseWidth: 5, 
 
        rearLength: '20%' 
 
       }, 
 
       pivot: { 
 
        radius: 5, 
 
        borderWidth: 5, 
 
        borderColor: '#000', 
 
        backgroundColor: '#fff' 
 
       } 
 
      } 
 
     }, 
 

 
     pane: { 
 
      startAngle:-90, 
 
      endAngle: 90, 
 
      center: ['50%', '55%'], 
 
       size: '85%', 
 
       startAngle: -90, 
 
       endAngle: 90,    
 
       background: { 
 
        backgroundColor: '#0187CC', 
 
        innerRadius: '110%', 
 
        outerRadius: '100%', 
 
        borderColor: 'transparent', 
 
        shape: 'arc', 
 
        
 
       }, 
 
     }, 
 

 
     // the value axis 
 
     yAxis: { 
 
      min: 0, 
 
      max: 30, 
 
      
 
      minorTickInterval: 'auto', 
 
      minorTickWidth: 0,    
 
      minorTickLength: 10, 
 
      minorTickPosition: 'inside', 
 
      minorTickColor: '#0187CC',    
 

 
      tickPixelInterval: 30, 
 
      tickWidth: 10, 
 
      tickPosition: 'inside', 
 
      tickLength: 10, 
 
      tickColor: '#0187CC',   
 
      labels: { 
 
       step: 2, 
 
       rotation: 'auto' 
 
      }, 
 
      title: { 
 
       text: '' 
 
      }, 
 
      plotBands: [{    
 
       color: '#FFF' 
 
      } 
 
      ] 
 
     }, 
 

 
     series: [{ 
 
      name: 'Speed', 
 
      data: [20], 
 
      tooltip: { 
 
       valueSuffix: ' Mbps' 
 
      } 
 
     }] 
 

 
    }, 
 

 
    // Add some life 
 
    function (chart) { 
 
     if (!chart.renderer.forExport) { 
 
      setInterval(function() { 
 
       var point = chart.series[0].points[0], 
 
        newVal, 
 
        inc = Math.round((Math.random() - 0) * 0); 
 

 
       newVal = point.y + inc; 
 
       if (newVal < 0 || newVal > 200) { 
 
        newVal = point.y - inc; 
 
       } 
 

 
       point.update(newVal); 
 

 
      }, 3000); 
 
     } 
 
    }); 
 
});
.highcharts-title, .highcharts-button, .highcharts-data-labels, .highcharts-tooltip, .highcharts-axis path:last-child , .highcharts-axis path:first-child, .highcharts-axis path:nth-child(13){ 
 
\t display: none; 
 
} 
 

 

 
.highcharts-axis-labels text{ 
 
\t fill: #000 !important; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script> 
 
<script src="https://code.highcharts.com/highcharts.js"></script> 
 
<script src="https://code.highcharts.com/highcharts-more.js"></script> 
 
<script src="https://code.highcharts.com/modules/exporting.js"></script> 
 
<script src="meter.js"></script> 
 

 

 
<div id="meter" style="min-width: 310px; max-width: 400px; height: 300px; margin: 0 auto"></div>

+0

tun Sie Verzögerung wollen basierend auf einer Bedingung oder genau, warum Sie benötigen zu verzögern? – Nitish

+0

Sie können eine Animation hinzufügen: {duration: 2000} in Ihrer Serie, um die Animation Ihrer Nadel zu ändern. Hier finden Sie Informationen zu diesem Parameter in Highcharts API: http://api.highcharts.com/highcharts#plotOptions.gauge.animation –

Antwort

0

In Ihrem plotOptions` Attribute, fügen Sie den folgenden Code ein:

series: { 
    animation: { 
     duration: 2000 
    } 
} 

Dies wird die Gauge-Nadel verursacht bis zu starten langsamer. Erhöhen Sie die Zahl, um sie zu verlangsamen. Verringere die Zahl, um sie zu beschleunigen.

Siehe auch das aktualisierte Code-Snippet unten.

Ich hoffe, das ist hilfreich!

$(function() { 
 

 
    $('#meter').highcharts({ 
 

 
     chart: { 
 
      type: 'gauge', 
 
      plotBackgroundColor: null, 
 
      plotBackgroundImage: null, 
 
      plotBorderWidth: 0, 
 
      plotShadow: false 
 
     }, 
 
     credits: { 
 
      enabled: false 
 
     }, 
 
     title: { 
 
      text: '' 
 
     }, 
 
     // 
 
     plotOptions: { 
 
      gauge: { 
 
       dataLabels: { 
 
        enabled: false 
 
       }, 
 
       dial: { 
 
        radius: '70%', 
 
        backgroundColor: '#000', 
 
        topWidth: 1, 
 
        baseWidth: 5, 
 
        rearLength: '20%' 
 
       }, 
 
       pivot: { 
 
        radius: 5, 
 
        borderWidth: 5, 
 
        borderColor: '#000', 
 
        backgroundColor: '#fff' 
 
       } 
 
      }, 
 
      series: { 
 
       animation: { 
 
        duration: 2000 
 
       } 
 
      } 
 

 
     }, 
 

 
     pane: { 
 
      startAngle:-90, 
 
      endAngle: 90, 
 
      center: ['50%', '55%'], 
 
       size: '85%', 
 
       startAngle: -90, 
 
       endAngle: 90,    
 
       background: { 
 
        backgroundColor: '#0187CC', 
 
        innerRadius: '110%', 
 
        outerRadius: '100%', 
 
        borderColor: 'transparent', 
 
        shape: 'arc', 
 
        
 
       }, 
 
     }, 
 

 
     // the value axis 
 
     yAxis: { 
 
      min: 0, 
 
      max: 30, 
 
      
 
      minorTickInterval: 'auto', 
 
      minorTickWidth: 0,    
 
      minorTickLength: 10, 
 
      minorTickPosition: 'inside', 
 
      minorTickColor: '#0187CC',    
 

 
      tickPixelInterval: 30, 
 
      tickWidth: 10, 
 
      tickPosition: 'inside', 
 
      tickLength: 10, 
 
      tickColor: '#0187CC',   
 
      labels: { 
 
       step: 2, 
 
       rotation: 'auto' 
 
      }, 
 
      title: { 
 
       text: '' 
 
      }, 
 
      plotBands: [{    
 
       color: '#FFF' 
 
      } 
 
      ] 
 
     }, 
 

 
     series: [{ 
 
      name: 'Speed', 
 
      data: [20], 
 
      tooltip: { 
 
       valueSuffix: ' Mbps' 
 
      } 
 
     }] 
 

 
    }, 
 

 
    // Add some life 
 
    function (chart) { 
 
     if (!chart.renderer.forExport) { 
 
      setInterval(function() { 
 
       var point = chart.series[0].points[0], 
 
        newVal, 
 
        inc = Math.round((Math.random() - 0) * 0); 
 

 
       newVal = point.y + inc; 
 
       if (newVal < 0 || newVal > 200) { 
 
        newVal = point.y - inc; 
 
       } 
 

 
       point.update(newVal); 
 

 
      }, 3000); 
 
     } 
 
    }); 
 
});
.highcharts-title, .highcharts-button, .highcharts-data-labels, .highcharts-tooltip, .highcharts-axis path:last-child , .highcharts-axis path:first-child, .highcharts-axis path:nth-child(13){ 
 
\t display: none; 
 
} 
 

 

 
.highcharts-axis-labels text{ 
 
\t fill: #000 !important; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script> 
 
<script src="https://code.highcharts.com/highcharts.js"></script> 
 
<script src="https://code.highcharts.com/highcharts-more.js"></script> 
 
<script src="https://code.highcharts.com/modules/exporting.js"></script> 
 
<script src="meter.js"></script> 
 

 

 
<div id="meter" style="min-width: 310px; max-width: 400px; height: 300px; margin: 0 auto"></div>

+0

Vielen Dank für Ihre Antwort. Was ich meinte, war eine Verzögerung der Nadelanimation beim Start. Ich muss die Nadelanimation nach dem vollständigen Laden der Seite starten. –

+0

@SubinGeorge '$ (document) .ready()' sollte darauf achten, wenn Sie jQuery verwenden. Welche anderen Gegenstände haben Sie auf der Seite geladen? Vielleicht könnten Sie entweder: 1) sie zuerst in der Reihenfolge von JS-bezogenen Elementen platzieren, die geladen werden, mit dem Diagrammcode unten, oder 2) eine Verzögerung für den Diagrammcode festlegen, der von einem anderen zuerst geladenen Element abhängig ist. –