2016-07-14 21 views
-1

高チャートでは、次のような配列があります。 しかし、配列の最高値を返すことによって極端な値を設定しようとすると、NaNエラーが表示されます。 iが最大値を取得しようとしました複雑なデータ構造のリストを処理する方法

function aoDashboardData() { 
var data = [ 

    {  type: "", 
      data: [{ 
       x: 0.0, 
       low: Date.UTC(2016, 2, 15), 
       high: Date.UTC(2016, 4, 10), 
       color: "#4B0081" 
      }, 
      { 
       x: 0.0, 
       low: Date.UTC(2016, 4, 15), 
       high: Date.UTC(2016, 6, 15), 
       color: "#00BFFE" 
      }, 
      { 
       x: 0.0, 
       low: Date.UTC(2016, 6, 20), 
       high: Date.UTC(2016, 8, 0), 
       color: "#0047AB" 
      }, 
      { 
       x: 0.0, 
       low: Date.UTC(2016, 8, 5), 
       high: Date.UTC(2016, 10, 15), 
       color: "#4682B4" 
      }, 
      { 
       x: 0.0, 
       low: Date.UTC(2016, 10, 20), 
       high: Date.UTC(2016, 12, 31), 
       color: "#008081" 
      }] 
     }, 
     { 
      type: 'line', 
      data: [ 
       { 
        x: 0.0, 
        y: Date.UTC(2016, 2, 15), 
        marker: { 
         symbol: 'url(/../Content/Img/monitor.png)', 
        } 
       }, 
       { 
        x: 0.0, 
        y: Date.UTC(2016, 4, 10), 
        marker: { 
         symbol: 'url(/../Content/Img/optimise.png)', 
        } 
       }, 
       { 
        x: 0.0, 
        y: Date.UTC(2016, 6, 15), 
        marker: { 
         symbol: 'url(/../Content/Img/pilot.png)', 
        } 
       }, 
       { 
        x: 0.0, 
        y: Date.UTC(2016, 8, 5), 
        marker: { 
         symbol: 'url(/../Content/Img/model.png)', 
        } 
       }, 
       { 
        x: 0.0, 
        y: Date.UTC(2016, 10, 15), 
        marker: { 
         symbol: 'url(/../Content/Img/deploy.png)', 
        } 
       } 

      ] 
     }, 



     { 
      type: "", 
      data: [{ 
       x: 1.0, 
       low: Date.UTC(2016, 2, 15), 
       high: Date.UTC(2016, 4, 10), 
       color: "#4B0081" 
      }, 
      { 
       x: 1.0, 
       low: Date.UTC(2016, 4, 15), 
       high: Date.UTC(2016, 6, 15), 
       color: "#00BFFE" 
      }, 
      { 
       x: 1.0, 
       low: Date.UTC(2016, 6, 20), 
       high: Date.UTC(2016, 8, 0), 
       color: "#0047AB" 
      }, 
      { 
       x: 1.0, 
       low: Date.UTC(2016, 8, 5), 
       high: Date.UTC(2016, 10, 15), 
       color: "#4682B4" 
      }, 
      { 
       x: 1.0, 
       low: Date.UTC(2016, 10, 20), 
       high: Date.UTC(2016, 12, 31), 
       color: "#008081" 
      }] 
     }, 
     { 
      type: 'line', 
      data: [ 
       { 
        x: 1.0, 
        y: Date.UTC(2016, 2, 15), 
        marker: { 
         symbol: 'url(/../Content/Img/monitor.png)', 
        } 
       }, 
       { 
        x: 1.0, 
        y: Date.UTC(2016, 4, 10), 
        marker: { 
         symbol: 'url(/../Content/Img/optimise.png)', 
        } 
       }, 
       { 
        x: 1.0, 
        y: Date.UTC(2016, 6, 15), 
        marker: { 
         symbol: 'url(/../Content/Img/pilot.png)', 
        } 
       }, 
       { 
        x: 1.0, 
        y: Date.UTC(2016, 8, 5), 
        marker: { 
         symbol: 'url(/../Content/Img/model.png)', 
        } 
       }, 
       { 
        x: 1.0, 
        y: Date.UTC(2016, 10, 15), 
        marker: { 
         symbol: 'url(/../Content/Img/deploy.png)', 
        } 
       } 

      ] 
     }, 

     { 
      type: "", 
      data: [{ 
       x: 2.0, 
       low: Date.UTC(2016, 2, 15), 
       high: Date.UTC(2016, 4, 10), 
       color: "#4B0081" 
      }, 
      { 
       x: 2.0, 
       low: Date.UTC(2016, 4, 15), 
       high: Date.UTC(2016, 6, 15), 
       color: "#00BFFE" 
      }, 
      { 
       x: 2.0, 
       low: Date.UTC(2016, 6, 20), 
       high: Date.UTC(2016, 8, 0), 
       color: "#0047AB" 
      }, 
      { 
       x: 2.0, 
       low: Date.UTC(2016, 8, 5), 
       high: Date.UTC(2016, 10, 15), 
       color: "#4682B4" 
      }, 
      { 
       x: 2.0, 
       low: Date.UTC(2016, 10, 20), 
       high: Date.UTC(2016, 12, 31), 
       color: "#008081" 
      }] 
     }, 
     { 
      type: 'line', 
      data: [ 
       { 
        x: 2.0, 
        y: Date.UTC(2016, 2, 15), 
        marker: { 
         symbol: 'url(/../Content/Img/monitor.png)', 
        } 
       }, 
       { 
        x: 2.0, 
        y: Date.UTC(2016, 4, 10), 
        marker: { 
         symbol: 'url(/../Content/Img/optimise.png)', 
        } 
       }, 
       { 
        x: 2.0, 
        y: Date.UTC(2016, 6, 15), 
        marker: { 
         symbol: 'url(/../Content/Img/pilot.png)', 
        } 
       }, 
       { 
        x: 2.0, 
        y: Date.UTC(2016, 8, 5), 
        marker: { 
         symbol: 'url(/../Content/Img/model.png)', 
        } 
       }, 
       { 
        x: 2.0, 
        y: Date.UTC(2016, 10, 15), 
        marker: { 
         symbol: 'url(/../Content/Img/deploy.png)', 
        } 
       } 

      ] 
     }, 


      { 
       type: "", 
       data: [{ 
        x: 3.0, 
        low: Date.UTC(2016, 2, 15), 
        high: Date.UTC(2016, 4, 10), 
        color: "#4B0081" 
       }, 
       { 
        x: 3.0, 
        low: Date.UTC(2016, 4, 15), 
        high: Date.UTC(2016, 6, 15), 
        color: "#00BFFE" 
       }, 
       { 
        x: 3.0, 
        low: Date.UTC(2016, 6, 20), 
        high: Date.UTC(2016, 8, 0), 
        color: "#0047AB" 
       }, 
       { 
        x: 3.0, 
        low: Date.UTC(2016, 8, 5), 
        high: Date.UTC(2016, 10, 15), 
        color: "#4682B4" 
       }, 
       { 
        x: 3.0, 
        low: Date.UTC(2016, 10, 20), 
        high: Date.UTC(2016, 12, 31), 
        color: "#008081" 
       }] 
      }, 
      { 
       type: 'line', 
       data: [ 
        { 
         x: 3.0, 
         y: Date.UTC(2016, 2, 15), 
         marker: { 
          symbol: 'url(/../Content/Img/monitor.png)', 
         } 
        }, 
        { 
         x: 3.0, 
         y: Date.UTC(2016, 4, 10), 
         marker: { 
          symbol: 'url(/../Content/Img/optimise.png)', 
         } 
        }, 
        { 
         x: 3.0, 
         y: Date.UTC(2016, 6, 15), 
         marker: { 
          symbol: 'url(/../Content/Img/pilot.png)', 
         } 
        }, 
        { 
         x: 3.0, 
         y: Date.UTC(2016, 8, 5), 
         marker: { 
          symbol: 'url(/../Content/Img/model.png)', 
         } 
        }, 
        { 
         x: 3.0, 
         y: Date.UTC(2016, 10, 15), 
         marker: { 
          symbol: 'url(/../Content/Img/deploy.png)', 
         } 
        } 

       ] 
      }, 

      { 
       type: "", 
       data: [{ 
        x: 4.0, 
        low: Date.UTC(2016, 2, 15), 
        high: Date.UTC(2016, 4, 10), 
        color: "#4B0081" 
       }, 
       { 
        x: 4.0, 
        low: Date.UTC(2016, 4, 15), 
        high: Date.UTC(2016, 6, 15), 
        color: "#00BFFE" 
       }, 
       { 
        x: 4.0, 
        low: Date.UTC(2016, 6, 20), 
        high: Date.UTC(2016, 8, 0), 
        color: "#0047AB" 
       }, 
       { 
        x: 1.0, 
        low: Date.UTC(2016, 8, 5), 
        high: Date.UTC(2016, 10, 15), 
        color: "#4682B4" 
       }, 
       { 
        x: 4.0, 
        low: Date.UTC(2016, 10, 20), 
        high: Date.UTC(2016, 12, 31), 
        color: "#008081" 
       }] 
      }, 
      { 
       type: 'line', 
       data: [ 
        { 
         x: 4.0, 
         y: Date.UTC(2016, 2, 15), 
         marker: { 
          symbol: 'url(/../Content/Img/monitor.png)', 
         } 
        }, 
        { 
         x: 4.0, 
         y: Date.UTC(2016, 4, 10), 
         marker: { 
          symbol: 'url(/../Content/Img/optimise.png)', 
         } 
        }, 
        { 
         x: 4.0, 
         y: Date.UTC(2016, 6, 15), 
         marker: { 
          symbol: 'url(/../Content/Img/pilot.png)', 
         } 
        }, 
        { 
         x: 4.0, 
         y: Date.UTC(2016, 8, 5), 
         marker: { 
          symbol: 'url(/../Content/Img/model.png)', 
         } 
        }, 
        { 
         x: 4.0, 
         y: Date.UTC(2016, 10, 15), 
         marker: { 
          symbol: 'url(/../Content/Img/deploy.png)', 
         } 
        } 

       ] 
      } 

      , 

      { 
       type: "", 
       data: [{ 
        x: 5.0, 
        low: Date.UTC(2016, 2, 15), 
        high: Date.UTC(2016, 4, 10), 
        color: "#4B0081" 
       }, 
       { 
        x: 5.0, 
        low: Date.UTC(2016, 4, 15), 
        high: Date.UTC(2016, 6, 15), 
        color: "#00BFFE" 
       }, 
       { 
        x: 5.0, 
        low: Date.UTC(2016, 6, 20), 
        high: Date.UTC(2016, 8, 0), 
        color: "#0047AB" 
       }, 
       { 
        x: 5.0, 
        low: Date.UTC(2016, 8, 5), 
        high: Date.UTC(2016, 10, 15), 
        color: "#4682B4" 
       }, 
       { 
        x: 5.0, 
        low: Date.UTC(2016, 10, 20), 
        high: Date.UTC(2016, 12, 31), 
        color: "#008081" 
       }] 
      }, 
      { 
       type: 'line', 
       data: [ 
        { 
         x: 5.0, 
         y: Date.UTC(2016, 2, 15), 
         marker: { 
          symbol: 'url(/../Content/Img/monitor.png)', 
         } 
        }, 
        { 
         x: 5.0, 
         y: Date.UTC(2016, 4, 10), 
         marker: { 
          symbol: 'url(/../Content/Img/optimise.png)', 
         } 
        }, 
        { 
         x: 5.0, 
         y: Date.UTC(2016, 6, 15), 
         marker: { 
          symbol: 'url(/../Content/Img/pilot.png)', 
         } 
        }, 
        { 
         x: 5.0, 
         y: Date.UTC(2016, 8, 5), 
         marker: { 
          symbol: 'url(/../Content/Img/model.png)', 
         } 
        }, 
        { 
         x: 5.0, 
         y: Date.UTC(2016, 10, 15), 
         marker: { 
          symbol: 'url(/../Content/Img/deploy.png)', 
         } 
        } 

       ] 
      } 
      , 

      { 
       type: "", 
       data: [{ 
        x: 6.0, 
        low: Date.UTC(2016, 2, 15), 
        high: Date.UTC(2016, 4, 10), 
        color: "#4B0081" 
       }, 
       { 
        x: 6.0, 
        low: Date.UTC(2016, 4, 15), 
        high: Date.UTC(2016, 6, 15), 
        color: "#00BFFE" 
       }, 
       { 
        x: 6.0, 
        low: Date.UTC(2016, 6, 20), 
        high: Date.UTC(2016, 8, 0), 
        color: "#0047AB" 
       }, 
       { 
        x: 6.0, 
        low: Date.UTC(2016, 8, 5), 
        high: Date.UTC(2016, 10, 15), 
        color: "#4682B4" 
       }, 
       { 
        x: 6.0, 
        low: Date.UTC(2016, 10, 20), 
        high: Date.UTC(2016, 12, 31), 
        color: "#008081" 
       }] 
      }, 
      { 
       type: 'line', 
       data: [ 
        { 
         x: 6.0, 
         y: Date.UTC(2016, 2, 15), 
         marker: { 
          symbol: 'url(/../Content/Img/monitor.png)', 
         } 
        }, 
        { 
         x: 6.0, 
         y: Date.UTC(2016, 4, 10), 
         marker: { 
          symbol: 'url(/../Content/Img/optimise.png)', 
         } 
        }, 
        { 
         x: 6.0, 
         y: Date.UTC(2016, 6, 15), 
         marker: { 
          symbol: 'url(/../Content/Img/pilot.png)', 
         } 
        }, 
        { 
         x: 6.0, 
         y: Date.UTC(2016, 8, 5), 
         marker: { 
          symbol: 'url(/../Content/Img/model.png)', 
         } 
        }, 
        { 
         x: 6.0, 
         y: Date.UTC(2016, 10, 15), 
         marker: { 
          symbol: 'url(/../Content/Img/deploy.png)', 
         } 
        } 

       ] 
      } 
      , 

      { 
       type: "", 
       data: [{ 
        x: 7.0, 
        low: Date.UTC(2016, 2, 15), 
        high: Date.UTC(2016, 4, 10), 
        color: "#4B0081" 
       }, 
       { 
        x: 7.0, 
        low: Date.UTC(2016, 4, 15), 
        high: Date.UTC(2016, 6, 15), 
        color: "#00BFFE" 
       }, 
       { 
        x: 7.0, 
        low: Date.UTC(2016, 6, 20), 
        high: Date.UTC(2016, 8, 0), 
        color: "#0047AB" 
       }, 
       { 
        x: 1.0, 
        low: Date.UTC(2016, 8, 5), 
        high: Date.UTC(2016, 10, 15), 
        color: "#4682B4" 
       }, 
       { 
        x: 7.0, 
        low: Date.UTC(2016, 10, 20), 
        high: Date.UTC(2016, 12, 31), 
        color: "#008081" 
       }] 
      }, 
      { 
       type: 'line', 
       data: [ 
        { 
         x: 7.0, 
         y: Date.UTC(2016, 2, 15), 
         marker: { 
          symbol: 'url(/../Content/Img/monitor.png)', 
         } 
        }, 
        { 
         x: 7.0, 
         y: Date.UTC(2016, 4, 10), 
         marker: { 
          symbol: 'url(/../Content/Img/optimise.png)', 
         } 
        }, 
        { 
         x: 7.0, 
         y: Date.UTC(2016, 6, 15), 
         marker: { 
          symbol: 'url(/../Content/Img/pilot.png)', 
         } 
        }, 
        { 
         x: 7.0, 
         y: Date.UTC(2016, 8, 5), 
         marker: { 
          symbol: 'url(/../Content/Img/model.png)', 
         } 
        }, 
        { 
         x: 7.0, 
         y: Date.UTC(2016, 10, 15), 
         marker: { 
          symbol: 'url(/../Content/Img/deploy.png)', 
         } 
        } 

       ] 
      } 
] 

return data; 

}

コードは次のとおりです。ここで

MinAssortmentValue = Math.min.apply(Math, chartlength); 

が更新jsFiddleリンクです:http://jsfiddle.net/sarav4gs/jbmk9tb1/3/

誰もが、私はそれを修正するのに役立つことはできますか?前もって感謝します!!

+0

あなたから 'chartlength'を得るのです:...

var chart = $('#ao-projectssummry-chart').highcharts(), minMaxValues = chart.series.reduce(function (collector, item, idx/*, list*/) { var dataMin = item.dataMin, dataMax = item.dataMax, minValue = Math.min(collector.minValue, dataMin), maxValue = Math.max(collector.maxValue, dataMax); if (minValue == dataMin) { collector.minValue = dataMin; collector.minValueItemIndex = idx; } if (maxValue == dataMax) { collector.maxValue = dataMax; collector.maxValueItemIndex = idx; } return collector; }, { minValue: Number.POSITIVE_INFINITY, maxValue: Number.NEGATIVE_INFINITY, minValueItemIndex: -1, maxValueItemIndex: -1 }), minAssortmentValue = minMaxValues.minValue, maxAssortmentValue = minMaxValues.maxValue; console.log("minMaxValues : ", minMaxValues); console.log("minAssortmentValue, maxAssortmentValue : ", minAssortmentValue, maxAssortmentValue); 

は、次のような出力を起こすんご提供フィドルのコンソールに切り取らだけで提供されたコードを貼り付けますか? –

+0

配列の最大値はどういう意味ですか?少しばかり説明できますか?最も高い値ですか、配列の最後の要素ですか? THTアプト – guradio

+0

@guradio申し訳ありませんが、私はあなたが完全なコードのために、このフィドルを参照することができ@NinaScholz最高値 – Sarav

答えて

2

...このコメントのmine-How to process a list of complex data structuresを参照してください。スケッチされたアプローチは、私がまだ比較したり抽出したりする予定のチャートアイテムのオブジェクトプロパティ

minMaxValues : Object { 
    minValue: 1458000000000, 
    maxValue: 1485820800000, 
    minValueItemIndex: 9, 
    maxValueItemIndex: 14 
} 
minAssortmentValue, maxAssortmentValue : 1458000000000 1485820800000 
+0

まず、あなたの時間とこの大きな助けに感謝します!私のコードでこのスニペットを試してみて、私のシナリオを達成できるかどうかを見てみましょう:) – Sarav

関連する問題