initChart(data) { this.chart = this.$echarts.init(this.$el, "macarons"); const {…
- User
initChart(data) { this.chart = this.el, "macarons"); const { keyListOne, keyListTwo, colorList, searchForm, formOne, formTwo, } = this; console.log("🚀 ~ initChart ~ searchForm:", searchForm, formOne, formTwo);
console.log("🚀 ~ initChart ~ rightHotel:", rightHotel, leftHotel); data = { priceOne: [ { label: "单间", value: [538.79, 596.57, 616.41, 361.05, 246.75, 246.75], }, { label: "套房", value: [837.67, 945.7, 947.76, 657.15, 613.04, 246.75], }, { label: "标间", value: [776.35, 844.67, 832.06, 437.1, 294.9, 246.75], }, ], timeOne: [ "04月30日", "05月01日", "05月02日", "05月03日", "05月04日", "05月05日", ], priceTwo: [ { label: "单间", value: [590.78, 632.23, 589.12, 463.77, 338.43, 280.41], }, { label: "套房", value: [1522.2, 1605.49, 1527.67, 1266.56, 982.07, 807.58], }, { label: "标间", value: [648.65, 708.25, 647.63, 494.6, 368.77, 302.86], }, ], timeTwo: [ "05月01日", "05月02日", "05月03日", "05月04日", "05月05日", "05月06日", "05月07日", "05月08日", ], }; // 根据查询条件 key取出左右两边查询数据 let timeData = data[keyListOne["timeData"]] || [];
let priceData = data[keyListOne["priceData"]] || []; priceData = JSON.parse(JSON.stringify(priceData));
let timeDataTwo = data[keyListTwo["timeData"]] || [];
let priceDataTwo = data[keyListTwo["priceData"]] || []; priceDataTwo = JSON.parse(JSON.stringify(priceDataTwo));
// 找到左右查询调整酒店类型 格式化 let leftHotel = this.formatter(formOne.hotelTypeOne); let rightHotel = this.formatter(formTwo.hotelTypeTwo); console.log("🚀 ~ initChart ~ rightHotel:", rightHotel, leftHotel);
// 格式化左右label 合并酒店到label中 priceData = priceData.map((item, index) => { item.label = leftHotel + "|" + item.label; return item; }); priceDataTwo = priceDataTwo.map((item, index) => { item.label = rightHotel + "|" + item.label; return item; });
- Assistant
- User
你虽然后面的数据填充了 0 但是前面的数据不对 用 mergeAndSortDates 将日期合并了之后 图表数据显示的日期位置不对,你看我现在的数据 ["04月30日","05月01日", "05月02日", "05月03日", "05月04日", "05月05日"] [ "05月01日", "05月02日", "05月03日", "05月04日", "05月05日", "05月06日", "05月07日", "05月08日", ] 合并之后4月30号是开头 但是 priceTwo 里面的数据的第一条数据不是4-30号的 是5-1号的
- Assistant
- User
const dateToPriceMap = originalDates.reduce((acc, date, index) => { acc[date] = item.value[index]; return acc; }, {}); 这里的数据能不能也填充下
- Assistant
Certainly! If you want to ensure that the
dateToPriceMapentries are properly handled even when not all dates have initial values, you might consider initializing the with all dates set to a default value (such as or ) before filling it with actual data. This ensures that every date in your is accounted for. - User
你现在把dateTwo的后面的数据填充0 了 能不能把第一个也填充一下
- Assistant
To ensure that
originalDatesfrom both datasets (timeOneandtimeTwo) have corresponding prices for each date in the combined , you need to pad both the beginning and the end where necessary. This means filling in with a default value (like or ) at positions where no data exists both before the first actual date and after the last actual date. - User
好像没有用 有的数据后面还是不是 0
- Assistant
To ensure that all entries in your price data arrays are correctly aligned and filled with zeros where the data doesn't exist, we need to ensure complete initialization and mapping for each date within the full date range (). If there's any misalignment still occurring, it's possible we didn't account correctly in the initial value mapping step.
- User
还是不对 是不是map 的原因啊 你map 只会循环长的那条数据后面添 0 但是短的那条数据循环次数不够 后面不能添0
- Assistant
- User
不对啊 你好像没懂我的意思 你给两个数组数据 priceOne ,priceTwo 如果priceOne比priceTwo 要短一点 那不是 priceOne map循环的次数要少一点吗 这样的话 后面日期的数据 短的那条就无法填充0 了
- Assistant
- User
苦笑 还是不对 5-7 5-8 的数据没有填充0
- Assistant