簡體   English   中英

HighStock 中 xAxis 的 softMin/softMax 未設置?

[英]softMin/softMax for xAxis in HighStock doesnt set?

查看 Highstock 文檔時,它說 xAxis 有一個 softMin 和 softMax,但是如果我利用日期,它似乎不能正確表示請求的日期范圍。

我一直需要執行以下操作:找到 xAxis 數據的間隔,然后在這些時間點用空數據填充數組的前端/末尾以正確傳達信息。

這有效,但我認為 HighStock 的軟值應該能夠處理這個問題。

在示例用例中:您可以設置以下內容:

{
    chart: {
      type: this.type || 'line',
    },
    title: {
      text: this.title || ''
    },
    credits: {
      enabled: false
    },
    rangeSelector: {
      inputEnabled: false,  // Specific to the Date Range Picker.
      enabled: false         // Specific to the Quick Selects for YTD, 6 mo, zoom.
    },
    navigator: {
      adaptToUpdatedData: true
    },
    scrollbar: {
      enabled: false
    },
    legend: {
      enabled: true
    },
    xAxis: {
      min: undefined,
      max: undefined,
      softMin: undefined,
      softMax: undefined,
      type: 'datetime',
      dateTimeLabelFormats: {
        day: '%b %e'
      }
    },
    // yAxis: {
    //   title: { text: ''}, opposite: true, type: 'linear'
    // },
    plotOptions: {
      series: {
        dataGrouping: {
          approximation: 'sum',
          groupPixelWidth: 25,
          forced: true,
          units: [
            ['minute', [30]],
            ['day', [1, 7, 15]],
            ['month', [1, 3, 6]]
          ]
        }
      }
    },
    series: []
  }

因此,我將日期視為數字, new Date().getTime()但如果我想設置 softMin 和 softMax,我想做如下操作:

xAxis: {
  softMin: new Date().getTime() - 1000 * 3600 * 24 * days_back
  softMax: new Date().getTime()
  }

其中 days_back 是用戶定義的變量,用於之前查看的天數。

我填充系列信息的方式如下:

const endtime = new Date().getTime();   //The current definition of endtime is now as there is no data for the future.
    const starttime = endtime - 1000 * 3600 * 24 * days;
    opts.series = dataset.map((item, idx, arr) => {
      const name: string = item.name || '';
      const data: any[] = item.data || []; // data is a list of lists.    ][time_as_number, value],...]
      if (data.length > 1) {
        /// The purpose of this code block is to padd out the dataset to the start and end ranges.
        ///  While there is a softMin and softMax, it doesnt work too when with regards to dates.
        ///  This will padd the data to be represenative of the users base selection.
        ///  If the list of data has 0 or 1 points, there is not enough data to define an interval for the target range.
        const difference = data[1][0] - data[0][0];
        let low = data[1][0];
        while (low > starttime) {
          low -= difference;
          data.unshift([low, null]);
        }
        let high = data[data.length - 1][0];
        while (high < endtime) {
          high += difference;
          data.push([high, null]);
        }
      }
      return {
        marker: { enabled: true },
        showInNavigator: true,
        type: 'line',
        name,
        data
      };
    });

有什么我應該考慮的東西嗎? 根據文檔的 min/max/minRange/maxRange 不是我想要分配的正確鍵。

為便於理解,HighStock 文檔位於此處: https ://api.highcharts.com/highstock/xAxis.softMin

這是一個示例: https ://jsfiddle.net/sp18efkb/ 您將在此示例中看到我設置了 softMin 但它沒有反映出來。 如果我使用chart對象,它就可以工作。 似乎雖然根據 API 是有效的,但它不是有效或受監控的屬性。

查看 HighStock 圖表時,如果您正在查看此圖表,則需要設置一個額外的變量。

在 xAxis 中,您需要將屬性ordinal屬性設置為 false。 為了使導航器以相同的方式運行,您需要使用該屬性,將 softmin 和 soft max 設置為相同,並關閉序數。

它看起來像這樣:

...

  navigator: {
    adaptToUpdatedData: true,
    xAxis: {
      ordinal: false,
      min: undefined,
      max: undefined,
      softMin: new Date().getTime() - 1000 * 3600 * 24 * 5,
      softMax: undefined
    }
  },
  xAxis: {
    ordinal: false,
    min: undefined,
    max: undefined,
    softMin: new Date().getTime() - 1000 * 3600 * 24 * 5,
    softMax: undefined,
    type: 'datetime',
    dateTimeLabelFormats: {
      day: '%b %e'
    }
  },
...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM