简体   繁体   English

HighStock 中 xAxis 的 softMin/softMax 未设置?

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

When looking at the Highstock documentation, it says there is a softMin and softMax for the xAxis, but if i leverage dates, it doesnt seem to properly represent the date ranges requested.查看 Highstock 文档时,它说 xAxis 有一个 softMin 和 softMax,但是如果我利用日期,它似乎不能正确表示请求的日期范围。

I have been needing to do the following: find the interval of the xAxis data, then padd the front/end of the array with null data at those timepoints to properly convey the info.我一直需要执行以下操作:找到 xAxis 数据的间隔,然后在这些时间点用空数据填充数组的前端/末尾以正确传达信息。

This works, but I figured HighStock's soft values should be able to handle this.这有效,但我认为 HighStock 的软值应该能够处理这个问题。

In a sample use case: you can set the following:在示例用例中:您可以设置以下内容:

{
    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: []
  }

So I look at the dates as if they are numbers, new Date().getTime() but if i want to set the softMin and softMax, I wanted to do something like:因此,我将日期视为数字, new Date().getTime()但如果我想设置 softMin 和 softMax,我想做如下操作:

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

where days_back is a user defined variable for how many days previously to look.其中 days_back 是用户定义的变量,用于之前查看的天数。

The way i pad out the series info is as follows:我填充系列信息的方式如下:

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
      };
    });

Is there something I am missing which i should be taking into account?有什么我应该考虑的东西吗? min/max/minRange/maxRange according to the docs are not the correct keys i wanted to assign to.根据文档的 min/max/minRange/maxRange 不是我想要分配的正确键。

For ease of understanding, HighStock Documentation is located here: https://api.highcharts.com/highstock/xAxis.softMin为便于理解,HighStock 文档位于此处: https ://api.highcharts.com/highstock/xAxis.softMin

Here is a sample: https://jsfiddle.net/sp18efkb/ You will see in this sample i set the softMin but it is not reflected.这是一个示例: https ://jsfiddle.net/sp18efkb/ 您将在此示例中看到我设置了 softMin 但它没有反映出来。 If i use a chart object though, it works.如果我使用chart对象,它就可以工作。 It seems that while it is valid according to the API, is not a valid or monitored property.似乎虽然根据 API 是有效的,但它不是有效或受监控的属性。

When looking at HighStock charts, there is an additional variable which needs to be set if you are looking at this.查看 HighStock 图表时,如果您正在查看此图表,则需要设置一个额外的变量。

In the xAxis you need to set the property ordinal property to false.在 xAxis 中,您需要将属性ordinal属性设置为 false。 In order to get the navigator to function in the same way, you need to use that property, set the softmin and soft max as the same, and also turn off ordinal.为了使导航器以相同的方式运行,您需要使用该属性,将 softmin 和 soft max 设置为相同,并关闭序数。

It would look something like this:它看起来像这样:

...

  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