简体   繁体   English

如何在高图中划分序列中的数据

[英]How to divide data from the series in highcharts

I want to process data from a .csv file to: 我想将.csv文件中的数据处理为:

  1. Divide the data coming in by 10, eg, 588 => 58.8 将输入的数据除以 10,例如588 => 58.8
  2. Remove outliers from the data or to change to zero, eg, 8888 => 0 从数据中删除异常值或更改为零,例如8888 => 0

Here is my javascript, I appreciate the help!! 这是我的JavaScript,感谢您的帮助!!

$.get('http://www.geoinc.org/Dropbox/geo/sites/GC_ROOM/charts/hassayampa.csv', function(data)
   {
      // Split the lines
      var lines = data.split('\n');
      var i = 0;
      var csvData = [];



      // Iterate over the lines and add categories or series
      $.each(lines, function(lineNo, line)
      {
         csvData[i] = line.split(',');

         i = i + 1;

      });


      var columns = csvData[0];

      var categories = [], series = [];


      for(var colIndex=0,len=columns.length; colIndex<len; colIndex++)
      {
         //first row data as series's name
         var seriesItem=
         {
            data:[],
            name:csvData[0][colIndex]
         };

         for(var rowIndex=1,rowCnt=csvData.length; rowIndex<rowCnt; rowIndex++)
         {
            //first column data as categories,
            if (colIndex == 0)
            {
               categories.push(csvData[rowIndex][0]);
            }
            else if(parseFloat(csvData[rowIndex][colIndex])) // <-- here
            {
               seriesItem.data.push(parseFloat(csvData[rowIndex][colIndex])); 
            }
         };
         //except first column
         if(colIndex>0)series.push(seriesItem);
      }         



      // Create the chart
      var chart = new Highcharts.Chart(
      {
         chart:
         {
            renderTo: 'test',
            type: 'line',
            zoomType: 'x',
         },
         title: {
                text: 'Daily Average Temperature',
                x: -20 //center
            },
            subtitle: {
                text: 'Source: HASSAYAMPA',
                x: -20
            },

         xAxis: 
         {
            categories: categories,
            labels:
            {
               step: 80,
            },
            tickWidth: 0
         },
         yAxis: 
         {
                    title: {
                    text: 'Temperature (\xB0C)'
                },
            //min: 0
         },
         tooltip:
         {
            formatter: function()
            {
               return '<b>'+ this.series.name +'</b><br/>'+ this.x +': '+ this.y +'\xB0C';
            }
         },
         legend:
         {
            layout: 'vertical',
            //backgroundColor: '#FFFFFF',
            //floating: true,
            align: 'left',
            //x: 100,
            verticalAlign: 'top',
            //y: 70,
            borderWidth: 0
         },

         plotOptions:
         {
            area:
            {
               animation: false,
               stacking: 'normal',
               lineColor: '#666666',
               lineWidth: 1,
               marker:
               {
                  lineWidth: 1,
                  lineColor: '#666666'
               }
            }
         },
         series: series
      });

   });      

I'm not sure what you are asking, but I'll take a shot at it... 我不确定您要问的是什么,但我会照做的...

First things first, this snippet of code is not sound. 首先,此代码段并不完善。 It'll not only skip NaNs but 0s as well (which is valid numeric data): 它不仅会跳过NaN,还会跳过0(这是有效的数字数据):

else if(parseFloat(csvData[rowIndex][colIndex]))
{
    seriesItem.data.push(parseFloat(csvData[rowIndex][colIndex])); 
}

Instead I'd do: 相反,我会这样做:

//first column data as categories,
if (colIndex == 0)
{
   categories.push(csvData[rowIndex][0]);
}
else
{
    var fVal = parseFloat(csvData[rowIndex][colIndex]);
    if (!isNaN(fVal))
    {
        fVal = fVal / 10.0; //<-- here's the division!!
        seriesItem.data.push(fVal);
    }   
}

As far as how to exclude outliers, the big question there is how do you want to exclude outliers? 至于如何排除离群值,最大的问题是您要如何排除离群值? A simple min/max criteria? 一个简单的最小/最大标准? Then just check that fVal is within those limits before seriesItem.data.push... 然后只需在系列项。数据。推之前检查fVal是否在那些限制内...

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

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