增加模拟数据以及模拟动态曲线图 1868/1 1868/head
authorCaisking <Casiking@zhihuishixun.com>
Thu, 19 Jun 2025 06:37:31 +0000 (14:37 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Thu, 19 Jun 2025 06:37:31 +0000 (14:37 +0800)
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/detection/BPDetectBeginView.h
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPModel.cpp
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/detection/BPDetectBeginView.cpp
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/detection/BPDetectFirstView.cpp

index 5c130bf..3952a6b 100644 (file)
@@ -23,7 +23,7 @@ namespace OHOS
         bool AddButton();
         bool InitLable();
         bool Initbackground();
-
+        void InitChartView();
     
         void UpdateTimeText(int data);
 
@@ -36,6 +36,10 @@ namespace OHOS
         UILabelExt *timeLabel = nullptr;
         UILabel*timenumLabel = nullptr;
 
+        Point testData[100];
+        UIChartDataSerial *dataSerial{nullptr};
+        UIChartPolyline *datachart = nullptr;
+
         UIViewGroup *group{nullptr};
     };
 }
index 6c37bc6..94d45d4 100644 (file)
@@ -192,7 +192,7 @@ static uint16 CalibrationFlag = 0;
     // 倒计时
     Time--;
     // 提前检查无效时间
-    if (Time <= 0)
+    if (Time < 0)
     {
       BPModel::GetInstance()->BP_StopTimer();
       BPModel::GetInstance()->BP_SetState(BPState::BP_NORMAL);
index f5368f2..4b8d4a0 100644 (file)
@@ -69,19 +69,81 @@ namespace OHOS
                 delete timenumLabel;
                 timenumLabel = nullptr;
             }
+            if(dataSerial != nullptr)
+            {
+                datachart->ClearDataSerial();
+                delete dataSerial;
+                dataSerial = nullptr;
+            }
+            if(datachart != nullptr)
+            {
+                delete datachart;
+                datachart = nullptr;
+            }
         }
         delete group;
         group = nullptr;
         
     }
     /* -------------------------------------------------------------------------- */
-    //倒计时更新时间文本
-    void BPDetectBeginView::UpdateTimeText(int data)
-    {
-        if(timenumLabel != nullptr && data >= 0 && data <= BP_CHECK_TIME_MAX)
-        {
+    // 倒计时更新时间文本
+    void BPDetectBeginView::UpdateTimeText(int data) {
+        if (timenumLabel != nullptr && data >= 0 && data <= BP_CHECK_TIME_MAX) {
             timenumLabel->SetText(std::to_string(data).c_str());
         }
+        // 生成正常血压范围(60~200)的随机数更新数据
+        for (int i = 0; i < 100; i++) {
+            testData[i].y = rand() % (210 - 60) + 60;
+        }
+
+        // 更新图表数据
+        if (datachart && dataSerial) {
+            dataSerial->ClearData();
+            dataSerial->AddPoints(testData, 100);
+            datachart->AddDataSerial(dataSerial);
+            RootView::GetInstance()->Invalidate();
+        }
+    }
+
+
+    void BPDetectBeginView::InitChartView()
+    {
+         /*
+            测试数据 100条
+        */
+        for (int i = 0; i < 100; i++) {
+            testData[i].x = i;
+            testData[i].y = 100; 
+        }
+
+        //初始化图表控件
+        if (datachart == nullptr) {
+            datachart = new UIChartPolyline();
+        }
+        datachart->SetPosition(56, 105);        
+        datachart->Resize(317, 136);        
+        datachart->SetViewId("uiChart");
+        datachart->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
+
+        //设置坐标轴为透明
+        UIXAxis& uiChartXAxis = datachart->GetXAxis();
+        UIYAxis& uiChartYAxis = datachart->GetYAxis();
+        uiChartXAxis.SetMarkNum(100);
+        uiChartXAxis.SetDataRange(0, 100);
+        uiChartXAxis.SetLineColor(Color::GetColorFromRGBA(0x00, 0x00, 0x00, 0x00));    
+        uiChartYAxis.SetMarkNum(5);
+        uiChartYAxis.SetDataRange(60, 210);
+        uiChartYAxis.SetLineColor(Color::GetColorFromRGBA(0x00, 0x00, 0x00, 0x00));
+
+        //设置数据曲线
+        dataSerial = new UIChartDataSerial();
+        dataSerial->SetMaxDataCount(100);
+        dataSerial->AddPoints(testData, 100);
+        dataSerial->SetFillColor(Color::GetColorFromRGBA(0x0b, 0xe4, 0x43, 0xff));
+        dataSerial->SetLineColor(Color::GetColorFromRGBA(0xf1, 0x0a, 0x0a, 0xff));
+        dataSerial->EnableGradient(false);
+        datachart->AddDataSerial(dataSerial);
+        datachart->SetGradientOpacity(0, 0);
     }
     /* -------------------------------------------------------------------------- */
     /***
@@ -99,10 +161,13 @@ namespace OHOS
 
         InitUILabel(timenumLabel, 133, 300, 200, 200, "timenumLabel", "30", DEFAULT_VECTOR_FONT_FILENAME, 100);
         
+        InitChartView();
+
         group->Add(calibrationLabel);
         group->Add(remindLabel);
         group->Add(timeLabel);
         group->Add(timenumLabel);
+        group->Add(datachart);
 
         return true;
     }
@@ -117,7 +182,7 @@ namespace OHOS
         background->SetSrc(BPBACKPATH);
 
         lineground = new UIImageView();
-        lineground->SetPosition(49, 95, 356, 161);
+        lineground->SetPosition(55, 95, 356, 161);
         lineground->SetSrc(BPLINEPATH);
 
         group->Add(background);
index 5b2d1ae..ed95293 100644 (file)
@@ -134,8 +134,8 @@ namespace OHOS
         if (bpchart == nullptr) {
             bpchart = new UIChartPolyline();
         }
-        bpchart->SetPosition(59, 203);        
-        bpchart->Resize(315, 150);        
+        bpchart->SetPosition(56, 205);        
+        bpchart->Resize(317, 136);        
         bpchart->SetViewId("uiChart");
         bpchart->SetStyle(STYLE_BACKGROUND_OPA, 0x00);