Browse Source

feat: [情绪探底雷达]代码提交

aiEmotion
yangchunyan 4 weeks ago
parent
commit
146c896f8c
  1. 553
      src/views/components/emotionalBottomRadar.vue
  2. 6
      src/views/emotionsEcharts.vue

553
src/views/components/emotionalBottomRadar.vue

@ -0,0 +1,553 @@
<template>
<div ref="bottomRadarRef" id="bottomRadarChart"></div>
</template>
<script setup>
import { ref } from 'vue'
import * as echarts from 'echarts'
const bottomRadarRef = ref(null)
function initEmotionalBottomRadar(KlineData, barAndLineData) {
console.log('KlineData, barAndLineData---', KlineData, barAndLineData)
let bottomRadarChartDom = document.getElementById('bottomRadarChart')
let bottomRadarChart = echarts.init(bottomRadarChartDom)
// -x
let dateArray = KlineData.map(subArray => subArray[0])
// k线
let kLineDataArray = KlineData.map(subArray => subArray.slice(1, 5))
// 线
let redLineDataArray = barAndLineData.map(subArray => subArray[1])
//
let barTotalDataArray = barAndLineData.map(subArray => subArray.slice(2, 6))
//
// barTotalDataArray[0] = [0, 0, 0, 0]
// barTotalDataArray[8] = [1, 1, 1, 1]
// barTotalDataArray[9] = [0, 0, 1, 1]
// barTotalDataArray[13] = [1, 0, 1, 0]
// barTotalDataArray[16] = [0, 0, 1, 0]
//
let yellowBlockDataArray = []
let yellowLineDataArray = []
let purpleLineDataArray = []
let blueLineDataArray = []
let transparentFillingDataArray = []
// 1 0-4
// 1 4
// 1 1-80
// 1 0-40
// base ECharts 4.x
barTotalDataArray.forEach((item) => {
if (item[0]) {
yellowBlockDataArray.push(4)
if (item[3]) {
// 40-4
blueLineDataArray.push(36)
if (item[2]) {
// 80-40
purpleLineDataArray.push(40)
transparentFillingDataArray.push(0)
} else {
purpleLineDataArray.push(0)
transparentFillingDataArray.push(0)
}
} else {
blueLineDataArray.push(0)
if (item[2]) {
// 80-4
purpleLineDataArray.push(76)
transparentFillingDataArray.push(0)
} else {
purpleLineDataArray.push(0)
transparentFillingDataArray.push(0)
}
}
} else if (!item[0]) {
yellowBlockDataArray.push(0)
if (item[3]) {
blueLineDataArray.push(40)
if (item[2]) {
// 80-40
purpleLineDataArray.push(40)
transparentFillingDataArray.push(0)
} else {
purpleLineDataArray.push(0)
transparentFillingDataArray.push(0)
}
} else {
blueLineDataArray.push(0)
if (item[2]) {
// 80-1base1
purpleLineDataArray.push(79)
transparentFillingDataArray.push(1)
} else {
purpleLineDataArray.push(0)
transparentFillingDataArray.push(0)
}
}
}
//
if (item[1]) {
yellowLineDataArray.push(1)
} else if (!item[1]) {
yellowLineDataArray.push(0)
}
})
//
let option = {
// backgroundColor: '#000046', //
tooltip: {
show: false, // tip
// echart; 4.x+showAxisPointer
trigger: 'axis',
axisPointer: {
type: 'cross',
crossStyle: {
color: '#999'
}
},
backgroundColor: 'rgba(255, 255, 255, 0.8)',
borderColor: '#ccc',
borderWidth: 1,
padding: 10,
textStyle: {
color: '#333'
},
formatter: function (params) {
let result = `<div style="font-weight: bold;">${params[0].name}</div>`
params.forEach(param => {
let value = param.value
let color = param.color
if (param.seriesType === 'candlestick') {
result += `<div style="color: ${color}"><i class="fa fa-square mr-1"></i>${param.seriesName}: 开 ${value[0]}, 收 ${value[1]}, 低 ${value[2]}, 高 ${value[3]}</div>`
} else {
result += `<div style="color: ${color}"><i class="fa fa-square mr-1"></i>${param.seriesName}: ${value}</div>`
}
})
return result
}
},
legend: {
// data: ['K线', '线', ''],
type: 'scroll',
pageButtonItemGap: 2,
pageButtonPosition: 'end',
textStyle: {
color: '#666'
}
},
grid: [
{
left: '3%',
right: '3%',
top: '20px',
bottom: '50%',
height: '300px',
// containLabel: true
},
{
left: '3%',
right: '3%',
top: '320px',
bottom: '25%',
height: '300px',
// containLabel: true
},
{
left: '3%',
right: '3%',
top: '620px',
bottom: '50px',
height: '300px',
// containLabel: true
}
],
xAxis: [
{
type: 'category',
data: dateArray,
gridIndex: 0,
boundaryGap: true, // y
axisLine: {
// show: false,
lineStyle: {
color: '#837b7b', // x线
}
},
axisTick: {
show: false
},
axisLabel: {
show: false
},
splitLine: {
show: false // x线
},
axisPointer: {
link: {
xAxisIndex: 'all'
}
}
},
{
type: 'category',
data: dateArray,
gridIndex: 1,
boundaryGap: true,
axisLine: {
// show: false,
lineStyle: {
// color: '#008000'
color: '#837b7b'
}
},
axisTick: {
show: false
},
axisLabel: {
show: false
},
splitLine: {
show: false
},
axisPointer: {
link: {
xAxisIndex: 'all'
}
}
},
{
type: 'category',
data: dateArray,
gridIndex: 2,
axisLine: {
lineStyle: {
color: '#837b7b'
}
},
axisTick: {
show: true, // 线
alignWithLabel: true,
lineStyle: {
color: '#999', //
width: 1, //
type: 'solid' // 线solid/dashed/dotted
}
},
axisLabel: {
color: '#000000',
interval: 'auto',
rotate: 45
},
splitLine: {
show: false
},
axisPointer: {
link: {
xAxisIndex: 'all'
}
}
}
],
yAxis: [
{
type: 'value',
gridIndex: 0,
splitNumber: 4,
axisLine: {
lineStyle: {
color: '#837b7b' // y
}
},
axisTick: {
show: true
},
axisLabel: {
width: 50, //
color: '#000000',
formatter: function (value, index) {
if (index === 0) {
return '0'
}
return value.toFixed(2)
}
},
splitLine: {
show: false,
lineStyle: {
color: '#837b7b',
type: 'dotted' // 线 dotted线 solid:线
}
},
// min: 4,
scale: true, // 0k线
},
{
type: 'value',
gridIndex: 1,
splitNumber: 3,
axisLine: {
lineStyle: {
color: '#837b7b'
}
},
axisTick: {
show: true
},
splitNumber: 5, //
axisLabel: {
width: 50, //
color: '#000000',
formatter: function(value, index) {
// y
if (index === 0) {
return '0'
} else if (index === 5) {
return ''
}
return value
}
},
splitLine: {
show: false,
lineStyle: {
color: '#837b7b',
type: 'dotted'
}
},
},
{
type: 'value',
gridIndex: 2,
splitNumber: 2,
axisLine: {
lineStyle: {
color: '#837b7b'
}
},
axisTick: {
show: true
},
splitNumber: 5, //
axisLabel: {
width: 50, //
color: '#000000',
formatter: function(value, index) {
if (index === 5) {
return ''
}
return value
}
},
splitLine: {
show: false,
lineStyle: {
color: '#837b7b',
type: 'dotted' // 线 dotted线 solid:线
}
},
splitNumber: 5,
min: function(value) {
return 0 //
},
max: function(value) {
return value.max + 10 // 10, x
}
}
],
dataZoom: [
{
type: 'slider',
xAxisIndex: [0, 2],
// start: 80,
// end: 100,
show: false
},
{
type: 'slider',
xAxisIndex: [0, 2],
// start: 80,
// end: 100,
show: false
},
{
type: 'slider',
xAxisIndex: [0, 2],
// or 20%
// start: 80,
// end: 100,
show: false, //
borderColor: '#CFD6E3',
dataBackground: {
// 线
lineStyle: {
color: '#CFD6E3'
},
//
areaStyle: {
color: 'rgba(241,243,247,0.5)'
}
}
},
],
series: [
{
name: 'K线',
type: 'candlestick',
data: kLineDataArray,
xAxisIndex: 0,
yAxisIndex: 0,
itemStyle: {
color: '#ef232a', // ()
color0: '#14b143', // (绿)
borderColor: '#ef232a',
borderColor0: '#14b143',
normal: {
color: '#ef232a', // ()
color0: '#14b143', // (绿)
borderColor: '#ef232a',
borderColor0: '#14b143',
opacity: function(params) {
// > 线
return params.data[2] > params.data[1] ? 0 : 1
}
}
}
},
{
name: '红线',
type: 'line',
data: redLineDataArray,
xAxisIndex: 1,
yAxisIndex: 1,
symbol: 'none',
sampling: 'average',
itemStyle: {
normal: {
color: '#ef232a'
}
},
areaStyle: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{ offset: 0, color: 'rgba(33, 150, 243, 0.4)' },
{ offset: 1, color: 'rgba(33, 150, 243, 0)' }
]
}
}
},
{
name: '基础base',
type: 'bar',
stack: 'total',
// barGap: '-100%', //
xAxisIndex: 2,
yAxisIndex: 2,
barCategoryGap: '0%',
itemStyle: {
normal: {
color: '#ffffff',
borderWidth: 0,
}
},
data: transparentFillingDataArray,
},
{
name: '黄色块',
type: 'bar',
stack: 'total',
// barGap: '-100%', //
xAxisIndex: 2,
yAxisIndex: 2,
barCategoryGap: '0%', // 0
itemStyle: {
normal: {
color: 'rgba(255, 255, 0, 1)',
borderWidth: 0,
//
label: {
show: (params) => {
return yellowLineDataArray[params.dataIndex] > 0
},
position: 'top',
textStyle: {
color: 'rgba(255, 255, 0, 1)'
},
formatter: (params) => {
return yellowLineDataArray[params.dataIndex] > 0 ? '加仓资金' : ''
}
}
}
},
data: yellowBlockDataArray,
},
{
name: '蓝色',
type: 'bar',
stack: 'total',
xAxisIndex: 2,
yAxisIndex: 2,
barCategoryGap: '0%', // 0
label: {
show: true,
position: 'inside'
},
itemStyle: {
normal: {
color: 'rgba(34, 196, 190, 1)',
borderWidth: 0
}
},
data: blueLineDataArray
},
{
name: '紫色',
type: 'bar',
stack: 'total',
xAxisIndex: 2,
yAxisIndex: 2,
barCategoryGap: '0%', // 0
label: {
show: true,
position: 'inside'
},
itemStyle: {
normal: {
color: 'rgba(191, 87, 222, 1)',
borderWidth: 0
}
},
data: purpleLineDataArray
},
]
}
// 使
bottomRadarChart.setOption(option)
//
window.addEventListener('resize', () => {
bottomRadarChart.resize()
})
}
//
defineExpose({
initEmotionalBottomRadar
})
</script>
<style>
#bottomRadarChart{
width: 100%;
height: 1040px;
}
</style>

6
src/views/emotionsEcharts.vue

@ -1,12 +1,16 @@
<template> <template>
AI情绪大模型 AI情绪大模型
<emoEnergyConverter ref="emoEnergyConverterRef"></emoEnergyConverter> <emoEnergyConverter ref="emoEnergyConverterRef"></emoEnergyConverter>
<EmotionalBottomRadar ref="emotionalBottomRadarRef"></EmotionalBottomRadar>
</template> </template>
<script setup> <script setup>
import emoEnergyConverter from '@/views/components/emoEnergyConverter.vue' import emoEnergyConverter from '@/views/components/emoEnergyConverter.vue'
import EmotionalBottomRadar from '@/views/components/emotionalBottomRadar.vue'
import { ref, onMounted, onBeforeUnmount, toRef } from 'vue'; import { ref, onMounted, onBeforeUnmount, toRef } from 'vue';
import axios from "axios"; import axios from "axios";
const emoEnergyConverterRef = ref(null) const emoEnergyConverterRef = ref(null)
const emotionalBottomRadarRef = ref(null)
onMounted(()=>{ onMounted(()=>{
axios({ axios({
@ -24,6 +28,8 @@ onMounted(()=>{
}).then((res) => { }).then((res) => {
nextTick(()=>{ nextTick(()=>{
emoEnergyConverterRef.value.initQXNLZHEcharts(res.data.data.KLine20, res.data.data.QXNLZHQ) emoEnergyConverterRef.value.initQXNLZHEcharts(res.data.data.KLine20, res.data.data.QXNLZHQ)
//
emotionalBottomRadarRef.value.initEmotionalBottomRadar(res.data.data.KLine20, res.data.data.QXTDLD)
}) })
}) })
}) })

Loading…
Cancel
Save