Echarts--制作正玄函数形式的Echarts图

父组件

<template>
  <div>
//这是一个弹出框
    <a-modal :visible="visible" @cancel="close" width="80%">
      <div class="check-content">
        <div style="height: 500px">
          <line-chart :value="lineData" ref="lineitemcard" />
        </div>
      </div>
      <template #title>
        <span class="check-title">动作电流波形</span>
      </template>
      <template #footer>
       
      </template>
    </a-modal>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import LineChart from '../chart/LineChart.vue'
const lineData = ref<any>([])

const props = defineProps({
  visible: {
    type: Boolean,
    default: () => {
      return false
    },
  },
  id: {
    type: Number
  },
  refersh: {
    type: Function
  }
})

// 保存
const formRef = ref<any>()
const emit = defineEmits(['update:visible', 'update:rowId'])

const close = () => {
  emit('update:rowId', 0)
  formRef.value?.resetFields()
  emit('update:visible', false)
}

onMounted(() => {
})

</script>

<style lang="less" scoped>
.check-content {
  width: 100%;
  height: 100%;

  .check {}
}

.check-title {
  font-size: 16px;
  // font-weight: bold;
  color: #000000;
}
</style>
<style>
:deep(.ant-form-item) {
  margin-bottom: 0px !important;
}
</style>

波形电流的组件

<template>
  <div>
    <div ref="line" class="echarts" :style="{ width: '100%', height: '100%' }"></div>

  </div>
</template>

<script lang="ts" setup>
import * as echarts from 'echarts'
import { computed, onMounted, ref, watch } from 'vue'
const props = defineProps({
  value:{
    type:Array,
    default:[]
  }
})
let myChart: any = ref()
const line = ref()
const inits = () => {
    // 基于准备好的dom,初始化echarts实例 
    myChart = echarts.init(line.value)
    let option = {
        tooltip: {
            trigger: 'axis',
        },
        legend: {
            //   data: ['个体风险预测', '群体风险预测'],
        },
        // grid: {
        //     left: '3%',
        //     right: '4%',
        //     bottom: '3%',
        //     containLabel: true,
        // },
        dataZoom: [
            {
                type: 'slider', // 使用滑块类型的dataZoom
                start: 0, // dataZoom滑块的起始位置,为0表示一开始显示全部数据
                end: 100, // dataZoom滑块的结束位置,为100表示一开始显示全部数据
            },
            {
                type: 'inside', // 允许使用鼠标滚轮或触摸板进行缩放
                start: 0, // 同上
                end: 80, // 同上
            }
        ],
        xAxis: {
            type: 'value',
            // name: '相位(°)',
            interval: 90,  //坐标轴刻度标签的显示间隔
            min: 0,
            max: 3600,
        },
        yAxis: [
            //左边y轴
            {
                type: 'value',
                // name: '幅值(dB)',
                min: -10, // 最小值
                max: 70,
                interval: 40,
            },
        ],
        series: [
            {
                type: 'line',
                showSymbol: false,
                clip: true,
                data: generateData()
            },
        ],
    }
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option)
}

onMounted(() => {
    setTimeout(() => {

        inits()
        // 屏幕尺寸改变是调整echart尺寸
        window.addEventListener('resize', () => {
            myChart?.resize()
        })
    }, 1000);
})

watch(() => props.value, (newVal, oldVal) => {
    if (newVal) {
        inits()
    }
}
)

function func(x) {
    x /= 57.2;
    return Math.sin(x) * 40 + 30;
}
function generateData() {
    let data = [];
    for (let i = 0; i <= 3600; i += 0.1) {
        data.push([i, func(i)]);
    }
    return data;
}

</script>

<style lang="less" scoped>
</style>

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,我可以为您解答。首先,您需要安装一些必要的库,包括 TensorFlow、Keras、NumPy 和 Matplotlib。请在命令行中输入以下命令来安装它们: ``` pip install tensorflow keras numpy matplotlib ``` 然后,您可以按照以下步骤进行操作: 1. 导入必要的库: ```python import numpy as np import matplotlib.pyplot as plt from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, LSTM ``` 2. 定义一些超参数: ```python seq_len = 100 # 序列长度 step = 0.1 # 步长 input_size = 1 # 输入维度 output_size = 1 # 输出维度 hidden_size = 32 # 隐藏层维度 batch_size = 32 # 批量大小 epochs = 100 # 训练次数 ``` 3. 生成训练数据: ```python def generate_data(seq_len): seq = np.arange(0, seq_len * step, step) seq = np.sin(seq) return seq.reshape(-1, 1) train_data = generate_data(seq_len) ``` 4. 准备数据: ```python def create_dataset(data, seq_len): X = [] y = [] for i in range(len(data) - seq_len): X.append(data[i:i+seq_len]) y.append(data[i+seq_len]) return np.array(X), np.array(y) X_train, y_train = create_dataset(train_data, seq_len) ``` 5. 定义模型: ```python model = Sequential() model.add(LSTM(hidden_size, input_shape=(seq_len, input_size))) model.add(Dense(output_size)) model.compile(optimizer='adam', loss='mse') ``` 6. 训练模型: ```python history = model.fit(X_train, y_train, batch_size=batch_size, epochs=epochs) ``` 7. 可视化损失函数: ```python plt.plot(history.history['loss']) plt.title('Model loss') plt.ylabel('Loss') plt.xlabel('Epoch') plt.show() ``` 最后,您可以使用模型来预测函数并可视化结果: ```python test_data = generate_data(seq_len * 2) X_test, y_test = create_dataset(test_data, seq_len) y_pred = model.predict(X_test) plt.plot(test_data) plt.plot(range(seq_len, seq_len * 3), y_pred) plt.title('Predicted vs. actual') plt.legend(['Actual', 'Predicted']) plt.show() ``` 这将显示一个包含实际函数和模型预测值的形。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值