chart.js 3.14 KB
Newer Older
1 2 3 4 5
import moment from 'moment';

// mock data
const visitData = [];
const beginDay = new Date().getTime();
afc163's avatar
afc163 committed
6 7 8

const fakeY = [7, 5, 4, 2, 4, 7, 5, 6, 5, 9, 6, 3, 1, 5, 3, 6, 5];
for (let i = 0; i < fakeY.length; i += 1) {
9
  visitData.push({
jim's avatar
jim committed
10
    x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format('YYYY-MM-DD'),
afc163's avatar
afc163 committed
11 12 13 14 15 16 17 18
    y: fakeY[i],
  });
}

const visitData2 = [];
const fakeY2 = [1, 6, 4, 8, 3, 7, 2];
for (let i = 0; i < fakeY2.length; i += 1) {
  visitData2.push({
jim's avatar
jim committed
19
    x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format('YYYY-MM-DD'),
afc163's avatar
afc163 committed
20
    y: fakeY2[i],
21 22
  });
}
afc163's avatar
afc163 committed
23

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
const salesData = [];
for (let i = 0; i < 12; i += 1) {
  salesData.push({
    x: `${i + 1}ๆœˆ`,
    y: Math.floor(Math.random() * 1000) + 200,
  });
}
const searchData = [];
for (let i = 0; i < 50; i += 1) {
  searchData.push({
    index: i + 1,
    keyword: `ๆœ็ดขๅ…ณ้”ฎ่ฏ-${i}`,
    count: Math.floor(Math.random() * 1000),
    range: Math.floor(Math.random() * 100),
    status: Math.floor((Math.random() * 10) % 2),
  });
}
const salesTypeData = [
  {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
43
    x: 'ๅฎถ็”จ็”ตๅ™จ',
44 45 46
    y: 4544,
  },
  {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
47
    x: '้ฃŸ็”จ้…’ๆฐด',
48 49 50
    y: 3321,
  },
  {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
51
    x: 'ไธชๆŠคๅฅๅบท',
52 53 54
    y: 3113,
  },
  {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
55
    x: 'ๆœ้ฅฐ็ฎฑๅŒ…',
56 57 58
    y: 2341,
  },
  {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
59
    x: 'ๆฏๅฉดไบงๅ“',
60 61 62
    y: 1231,
  },
  {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
63
    x: 'ๅ…ถไป–',
64 65 66 67 68 69
    y: 1231,
  },
];

const salesTypeDataOnline = [
  {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
70
    x: 'ๅฎถ็”จ็”ตๅ™จ',
71 72 73
    y: 244,
  },
  {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
74
    x: '้ฃŸ็”จ้…’ๆฐด',
75 76 77
    y: 321,
  },
  {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
78
    x: 'ไธชๆŠคๅฅๅบท',
79 80 81
    y: 311,
  },
  {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
82
    x: 'ๆœ้ฅฐ็ฎฑๅŒ…',
83 84 85
    y: 41,
  },
  {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
86
    x: 'ๆฏๅฉดไบงๅ“',
87 88 89
    y: 121,
  },
  {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
90
    x: 'ๅ…ถไป–',
91 92 93 94 95 96
    y: 111,
  },
];

const salesTypeDataOffline = [
  {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
97
    x: 'ๅฎถ็”จ็”ตๅ™จ',
98 99 100
    y: 99,
  },
  {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
101
    x: '้ฃŸ็”จ้…’ๆฐด',
102 103 104
    y: 188,
  },
  {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
105
    x: 'ไธชๆŠคๅฅๅบท',
106 107 108
    y: 344,
  },
  {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
109
    x: 'ๆœ้ฅฐ็ฎฑๅŒ…',
110 111 112
    y: 255,
  },
  {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
113
    x: 'ๅ…ถไป–',
114 115 116 117 118 119 120
    y: 65,
  },
];

const offlineData = [];
for (let i = 0; i < 10; i += 1) {
  offlineData.push({
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
121
    name: `Stores ${i}`,
122 123 124 125 126 127
    cvr: Math.ceil(Math.random() * 9) / 10,
  });
}
const offlineChartData = [];
for (let i = 0; i < 20; i += 1) {
  offlineChartData.push({
jim's avatar
jim committed
128
    x: new Date().getTime() + 1000 * 60 * 30 * i,
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
    y1: Math.floor(Math.random() * 100) + 10,
    y2: Math.floor(Math.random() * 100) + 10,
  });
}

const radarOriginData = [
  {
    name: 'ไธชไบบ',
    ref: 10,
    koubei: 8,
    output: 4,
    contribute: 5,
    hot: 7,
  },
  {
    name: 'ๅ›ข้˜Ÿ',
    ref: 3,
    koubei: 9,
    output: 6,
    contribute: 3,
    hot: 1,
  },
  {
    name: '้ƒจ้—จ',
    ref: 4,
    koubei: 1,
    output: 6,
    contribute: 5,
    hot: 7,
  },
];

const radarData = [];
const radarTitleMap = {
  ref: 'ๅผ•็”จ',
  koubei: 'ๅฃ็ข‘',
  output: 'ไบง้‡',
  contribute: '่ดก็Œฎ',
  hot: '็ƒญๅบฆ',
};
jim's avatar
jim committed
169 170
radarOriginData.forEach(item => {
  Object.keys(item).forEach(key => {
171 172 173 174 175 176 177 178 179 180
    if (key !== 'name') {
      radarData.push({
        name: item.name,
        label: radarTitleMap[key],
        value: item[key],
      });
    }
  });
});

ๆ„š้“'s avatar
ๆ„š้“ committed
181
const getFakeChartData = {
182
  visitData,
afc163's avatar
afc163 committed
183
  visitData2,
184 185 186 187 188 189 190 191 192 193 194
  salesData,
  searchData,
  offlineData,
  offlineChartData,
  salesTypeData,
  salesTypeDataOnline,
  salesTypeDataOffline,
  radarData,
};

export default {
ๆ„š้“'s avatar
ๆ„š้“ committed
195
  'GET /api/fake_chart_data': getFakeChartData,
196
};