You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在FusionTime图表中实现7天间隔的X轴日期展示

Hey there! I ran into a similar issue with FusionTime's binning limitations before, so I can share a couple of workarounds that'll let you display 7-day intervals on your X-axis:

1. Preprocess Your Dataset (Most Reliable Approach)

Since FusionTime doesn't support 7 as a binning value, the most straightforward fix is to aggregate your data into 7-day chunks before feeding it to the chart. This way, you're in full control of the intervals, and the chart will render exactly what you want.

Here's a quick JavaScript example of how to do this (adjust the aggregation logic to match your data type—sum, average, etc.):

// Sample raw time-series data
const rawData = [
  { date: "2024-01-01", value: 150 },
  { date: "2024-01-02", value: 180 },
  { date: "2024-01-03", value: 165 },
  // ... add more data points
];

// Function to aggregate data into 7-day batches
function groupBy7Days(data) {
  const groupedData = [];
  let currentGroup = [];
  const firstDate = new Date(data[0].date);

  data.forEach((item) => {
    const currentDate = new Date(item.date);
    const daysFromStart = Math.floor((currentDate - firstDate) / (1000 * 60 * 60 * 24));

    // Start a new group every 7 days (after the first entry)
    if (daysFromStart % 7 === 0 && currentGroup.length > 0) {
      // Calculate aggregated value (here we're summing, replace with avg/min/max as needed)
      const groupTotal = currentGroup.reduce((sum, entry) => sum + entry.value, 0);
      groupedData.push({
        date: currentGroup[0].date, // Use the first day of the 7-day window as the label
        value: groupTotal
      });
      currentGroup = [];
    }
    currentGroup.push(item);
  });

  // Handle the final group of data
  if (currentGroup.length > 0) {
    const groupTotal = currentGroup.reduce((sum, entry) => sum + entry.value, 0);
    groupedData.push({
      date: currentGroup[0].date,
      value: groupTotal
    });
  }

  return groupedData;
}

// Use the processed data for your FusionTime chart
const processedData = groupBy7Days(rawData);

Once you have this aggregated dataset, pass it to FusionTime—your X-axis will automatically show 7-day intervals without needing any special binning config.

2. Customize X-Axis Labels & Ticks (No Data Changes Needed)

If you don't want to modify your raw dataset, you can override FusionTime's default X-axis behavior to only display labels every 7 days. This relies on custom formatting and tick configuration:

const chartConfig = {
  type: "timeseries",
  dataSource: {
    data: rawData, // Your original unprocessed data
    xAxis: {
      label: {
        // Custom formatter to show labels only every 7 days
        formatter: function(dateVal) {
          const firstDataDate = new Date(rawData[0].date);
          const dayDifference = Math.floor((dateVal - firstDataDate) / (1000 * 60 * 60 * 24));
          // Only return a label if we're at a 7-day interval from the start date
          return dayDifference % 7 === 0 ? dateVal.toLocaleDateString() : "";
        }
      },
      tickConfig: {
        // Set ticks to appear every 7 days
        interval: 7,
        intervalType: "day"
      }
    },
    // Disable built-in binning since we're handling intervals manually
    binning: {}
  }
};

Quick Notes on Both Approaches

  • Preprocessing is better for consistency, especially if you need to display aggregated values (like weekly totals). It avoids any rendering quirks with dynamic label hiding.
  • Custom X-axis config works great if you need to keep the raw data intact (e.g., for tooltips that show daily values) but only want weekly labels on the axis. Just double-check your date calculation logic to make sure labels align correctly.

内容的提问来源于stack exchange,提问作者A_J

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 07:57:38