瀏覽代碼

add compare and change chart type function

andy 5 月之前
父節點
當前提交
77c72da82a
共有 10 個文件被更改,包括 559 次插入99 次删除
  1. 67 4
      css/custom.css
  2. 二進制
      img/.DS_Store
  3. 1 0
      img/chart-bar.svg
  4. 1 0
      img/chart-line.svg
  5. 1 0
      img/chart-pie.svg
  6. 二進制
      img/finance/05.webp
  7. 二進制
      img/finance/09.webp
  8. 1 0
      img/table.svg
  9. 135 77
      index.html
  10. 353 18
      js/demo/text-to-chart.js

+ 67 - 4
css/custom.css

@@ -33,7 +33,7 @@ body{
 }
 
 #downloadButton{
-    margin:10px auto ;
+    /* margin:10px auto ; */
     background: #00448F;
     color:#fff;
     border-radius: .3rem;
@@ -101,7 +101,7 @@ padding: 30px;
 }
 
 .chartSettingBox{
-    height: 90vh;
+    /* height: 90vh; */
 }
 
 
@@ -172,6 +172,8 @@ padding: 30px;
     width: 95%;
     left: 25px;
     padding: 1rem;
+    z-index: 101;
+
    
 }
 
@@ -180,8 +182,8 @@ padding: 30px;
     bottom:5px;
     width: 95%;
     left: 25px;
+    z-index: 102;
     padding: 1rem;
-    z-index: 99;
 }
 
 #fixed_button .input-group{
@@ -199,7 +201,47 @@ padding: 30px;
 .setting_button_content{
 
 }
+.centered-div {
+    position: absolute;
+    width: 80%;
+    top: 30%;
+    left: 50%;
+    transform: translate(-50%, -50%);
+    text-align: center; /* 可選:內容置中 */
+    padding: 20px; /* 可選:內邊距 */
+    z-index: 101;
+  
+}
+#table-svg{
+    color: rgb(118, 208, 235);
+}
+#line-icon{
+    fill: rgb(118, 208, 235);
+    width: 20px;
+}
+#bar-icon{
+    fill:rgb(203, 139, 208);;
+    width: 20px;
+}
+#pie-icon{
+    fill: rgb(226, 197, 65);
+    width: 20px;
+}
+#table-icon{
+    fill: #6c757d;
+    width: 20px;
+}
+.example{
+    padding: 20px;
+    transition: 0.3s;
+    cursor: pointer;
+}
 
+.example:hover{
+
+   background: #f8f9fa;
+ 
+}
 .setting_button{
     position: fixed;
     top:300px;
@@ -304,7 +346,7 @@ padding: 30px;
 .img_box{
     position: absolute;
     bottom: 91px;
-    right: 36px;
+    right: 15px;
 
 }
 
@@ -333,6 +375,10 @@ padding: 30px;
     display: none;
 }
 
+#chartType{
+    display: none;
+}
+
 #logout{
     cursor: pointer;
 }
@@ -381,4 +427,21 @@ padding: 30px;
 #stop{
     background: none;
     border:none;
+}
+
+.compare{
+    display: none;
+}
+
+.chartType{
+    height: calc(1.5em + .75rem + 2px);
+    padding: .375rem .75rem;
+    font-size: 1rem;
+    font-weight: 400;
+    line-height: 1.5;
+    color: #6e707e;
+    background-color: #fff;
+    background-clip: padding-box;
+    border: 1px solid #d1d3e2;
+    border-radius: .35rem;
 }

二進制
img/.DS_Store


+ 1 - 0
img/chart-bar.svg

@@ -0,0 +1 @@
+<svg id="svgcolor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!-- Font Awesome Free 5.15.3 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z"/></svg>

+ 1 - 0
img/chart-line.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!-- Font Awesome Free 5.15.3 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M496 384H64V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-32c0-8.84-7.16-16-16-16zM464 96H345.94c-21.38 0-32.09 25.85-16.97 40.97l32.4 32.4L288 242.75l-73.37-73.37c-12.5-12.5-32.76-12.5-45.25 0l-68.69 68.69c-6.25 6.25-6.25 16.38 0 22.63l22.62 22.62c6.25 6.25 16.38 6.25 22.63 0L192 237.25l73.37 73.37c12.5 12.5 32.76 12.5 45.25 0l96-96 32.4 32.4c15.12 15.12 40.97 4.41 40.97-16.97V112c.01-8.84-7.15-16-15.99-16z"/></svg>

+ 1 - 0
img/chart-pie.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 544 512"><!-- Font Awesome Free 5.15.3 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M527.79 288H290.5l158.03 158.03c6.04 6.04 15.98 6.53 22.19.68 38.7-36.46 65.32-85.61 73.13-140.86 1.34-9.46-6.51-17.85-16.06-17.85zm-15.83-64.8C503.72 103.74 408.26 8.28 288.8.04 279.68-.59 272 7.1 272 16.24V240h223.77c9.14 0 16.82-7.68 16.19-16.8zM224 288V50.71c0-9.55-8.39-17.4-17.84-16.06C86.99 51.49-4.1 155.6.14 280.37 4.5 408.51 114.83 513.59 243.03 511.98c50.4-.63 96.97-16.87 135.26-44.03 7.9-5.6 8.42-17.23 1.57-24.08L224 288z"/></svg>

二進制
img/finance/05.webp


二進制
img/finance/09.webp


+ 1 - 0
img/table.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!-- Font Awesome Free 5.15.3 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M464 32H48C21.49 32 0 53.49 0 80v352c0 26.51 21.49 48 48 48h416c26.51 0 48-21.49 48-48V80c0-26.51-21.49-48-48-48zM224 416H64v-96h160v96zm0-160H64v-96h160v96zm224 160H288v-96h160v96zm0-160H288v-96h160v96z"/></svg>

+ 135 - 77
index.html

@@ -28,7 +28,7 @@
 
 <body id="page-top">
     <!-- Page Wrapper -->
-    <div id="wrapper">
+    <div id="wrapper" style="height: 130vh;">
         <!-- Sidebar -->
         <ul class="navbar-nav sidebar sidebar-dark accordion toggled d-none" id="accordionSidebar">
 
@@ -126,6 +126,57 @@
 
                 <!-- Begin Page Content -->
                 <div class="container-fluid">
+                    <div id="example_box" class="centered-div">
+                        <div class="row">
+                            <div class="col-lg-3">
+                                <div class="card example h-100" data-value="台股-2330 台積電 2024年每日收盤價"
+                                    onclick="handleClick(this)">
+                                    <p><svg id="line-icon" class="mr-2" xmlns="http://www.w3.org/2000/svg"
+                                            viewBox="0 0 512 512">
+                                            <path
+                                                d="M496 384H64V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-32c0-8.84-7.16-16-16-16zM464 96H345.94c-21.38 0-32.09 25.85-16.97 40.97l32.4 32.4L288 242.75l-73.37-73.37c-12.5-12.5-32.76-12.5-45.25 0l-68.69 68.69c-6.25 6.25-6.25 16.38 0 22.63l22.62 22.62c6.25 6.25 16.38 6.25 22.63 0L192 237.25l73.37 73.37c12.5 12.5 32.76 12.5 45.25 0l96-96 32.4 32.4c15.12 15.12 40.97 4.41 40.97-16.97V112c.01-8.84-7.15-16-15.99-16z" />
+                                        </svg>折線圖:</p>
+                                    <p>台股-2330 台積電 2024年每日收盤價</p>
+                                </div>
+                            </div>
+                            <div class="col-lg-3">
+                                <div class="card example  h-100" data-value="近一個月總計最多交易量的10支台股"
+                                    onclick="handleClick(this)">
+
+                                    <p><svg id="bar-icon" class="mr-2" xmlns="http://www.w3.org/2000/svg"
+                                            viewBox="0 0 512 512">
+                                            <path
+                                                d="M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z" />
+                                        </svg>柱狀圖:</p>
+                                    <p>近一個月總計最多交易量的10支台股</p>
+
+                                </div>
+                            </div>
+                            <div class="col-lg-3">
+                                <div class="card example  h-100" data-value="台股各產業市值占比" onclick="handleClick(this)">
+
+                                    <p><svg id="pie-icon" class="mr-2" xmlns="http://www.w3.org/2000/svg"
+                                            viewBox="0 0 512 512">
+                                            <path
+                                                d="M527.79 288H290.5l158.03 158.03c6.04 6.04 15.98 6.53 22.19.68 38.7-36.46 65.32-85.61 73.13-140.86 1.34-9.46-6.51-17.85-16.06-17.85zm-15.83-64.8C503.72 103.74 408.26 8.28 288.8.04 279.68-.59 272 7.1 272 16.24V240h223.77c9.14 0 16.82-7.68 16.19-16.8zM224 288V50.71c0-9.55-8.39-17.4-17.84-16.06C86.99 51.49-4.1 155.6.14 280.37 4.5 408.51 114.83 513.59 243.03 511.98c50.4-.63 96.97-16.87 135.26-44.03 7.9-5.6 8.42-17.23 1.57-24.08L224 288z" />
+                                        </svg>圓餅圖:</p>
+                                    <p>台股各產業市值占比</p>
+                                </div>
+                            </div>
+                            <div class="col-lg-3 ">
+                                <div class="card example  h-100" data-value="比較2021年和2024年nvda平均股價"
+                                    onclick="handleClick(this)">
+
+                                    <p><svg id="table-icon" class="mr-2" xmlns="http://www.w3.org/2000/svg"
+                                            viewBox="0 0 512 512">
+                                            <path
+                                                d="M464 32H48C21.49 32 0 53.49 0 80v352c0 26.51 21.49 48 48 48h416c26.51 0 48-21.49 48-48V80c0-26.51-21.49-48-48-48zM224 416H64v-96h160v96zm0-160H64v-96h160v96zm224 160H288v-96h160v96zm0-160H288v-96h160v96z" />
+                                        </svg>表格:</p>
+                                    <p>比較2021年和2024年nvda平均股價</p>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
                     <div class="row d-flex flex-wrap mb-4">
                         <div class="col-xl-5 col-lg-5 chartSettingBox d-none">
                             <div class="card shadow mb-4 h-100 pb-5">
@@ -156,14 +207,10 @@
                             <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between border-0 py-0"
                                 style="background: none;">
                                 <h6 class="m-0 font-weight-bold text-primary d-none">圖表輸出</h6>
-
                                 <!-- <p>語音辨識結果:<span id="record_text"> </span></p> -->
-
-
                                 <!-- <div class="text-center">
                                     <button id="downloadButton">下載圖表</button>
                                 </div> -->
-
                                 <!-- <div class="dropdown no-arrow">
                                     <a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink"
                                         data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
@@ -177,72 +224,69 @@
                                 </div> -->
                             </div>
                         </div>
-
-
                         <div class="col-xl-8 col-lg-8 chartSettingBox">
-                            <div class="card shadow mb-4 h-100">
-                                <!-- Card Header - Dropdown -->
-
-                                <!-- Card Body -->
-                                <div class="card-body chart_background p-0 chartSettingBox2">
-                                    <div class="chart-area">
-                                        <div id="chartDataLoading" class="h-100">
-                                            <div class="d-flex justify-content-center align-items-center h-100">
-                                                <div class="spinner-border" role="status">
-                                                    <span class="sr-only">Loading...</span>
-                                                </div>
+                            <!-- <div style="background: none; border: none;" class="mb-4"> -->
+                            <!-- Card Header - Dropdown -->
+
+                            <!-- Card Body -->
+                            <div class="card-body chart_background p-0 chartSettingBox2">
+                                <div class="chart-area">
+                                    <div id="chartDataLoading" class="h-100">
+                                        <div class="d-flex justify-content-center align-items-center h-100">
+                                            <div class="spinner-border" role="status">
+                                                <span class="sr-only">Loading...</span>
                                             </div>
                                         </div>
-                                        <div class="chart_box">
-                                            <div class="text-right">
-                                                <button id="downloadButton">下載圖表</button>
-                                            </div>
-                                            <!-- <div id="legend" class="mt-3"></div> -->
-                                            <div id="data_chart_box" class="chart_box2" style="position: relative;">
-                                                <h2 class="chart_title"></h2>
-                                                <!-- <div style="padding:0px 30px 30px;"> -->
-                                                <div id="data_chartJs_box"
-                                                    style="position: relative;  height: auto; text-align: center;">
-                                                    <canvas id="textToChart"></canvas>
-                                                    <!-- <div id="chart-label"></div> -->
-                                                    <!-- <div class="chart-line" id="chart-line"></div> -->
-
-                                                    <div id="chartdiv"></div>
-
-
-                                                </div>
-
-                                                <div id="unit_box" class="unit_box">
-                                                    <div class="unit_value"><span class="unit"></span></div>
-                                                </div>
-                                                <!-- </div> -->
-                                                <div id="img_box" class="img_box">
-                                                    <img id="img_box_url" src="" alt="">
-                                                </div>
-                                            </div>
+                                    </div>
+                                    <div class="chart_box">
+                                        <div class="d-flex justify-content-between mb-3">
+                                            <select id="chartType" class="chartType">
+                                                <option value="">圖表類型</option>
+                                                <option value="line">折線圖</option>
+                                                <option value="bar">柱狀圖</option>
+                                                <option value="doughnut">圓餅圖</option>
+                                            </select>
+                                            <button id="downloadButton">下載圖表</button>
                                         </div>
-                                        <div class="input-group pr-5 pl-5 compare mt-3 d-none">
-                                            <input type="text" style="position: relative ; z-index: 100;"
-                                                id="keyword_data_compare" class="form-control bg-white small"
-                                                placeholder="搜尋股票、ETF 或其他項目進行比較..." aria-label="Search"
-                                                aria-describedby="basic-addon2">
-                                            <div id="suggestions_compare" class="autocomplete-suggestions2"></div>
-                                            <div class="input-group-append">
-                                                <button class="btn btn-primary" type="button">
-                                                    <!-- <i class="fas fa-search fa-sm"></i> -->
-                                                    比較
-                                                </button>
+                                        <!-- <div id="legend" class="mt-3"></div> -->
+                                        <div id="data_chart_box" class="chart_box2" style="position: relative;">
+                                            <h2 class="chart_title"></h2>
+                                            <!-- <div style="padding:0px 30px 30px;"> -->
+                                            <div id="data_chartJs_box"
+                                                style="position: relative;  height: auto; text-align: center;">
+                                                <canvas id="textToChart"></canvas>
+                                                <!-- <div id="chart-label"></div> -->
+                                                <!-- <div class="chart-line" id="chart-line"></div> -->
+                                                <div id="chartdiv"></div>
+                                            </div>
 
+                                            <div id="unit_box" class="unit_box">
+                                                <div class="unit_value"><span class="unit"></span></div>
+                                            </div>
+                                            <!-- </div> -->
+                                            <div id="img_box" class="img_box">
+                                                <img id="img_box_url" src="" alt="">
                                             </div>
                                         </div>
                                     </div>
+                                    <div id="compare" class="input-group pr-5 pl-5 compare mt-3">
+                                        <input type="text" style="position: relative ; z-index: 100;"
+                                            id="keyword_data_compare" class="form-control bg-white small"
+                                            placeholder="搜尋股票、ETF 或其他項目進行比較..." aria-label="Search"
+                                            aria-describedby="basic-addon2">
+                                        <div id="suggestions_compare" class="autocomplete-suggestions2"></div>
+                                        <div class="input-group-append">
+                                            <button id="data_compare" class="btn btn-primary" type="button">
+                                                <!-- <i class="fas fa-search fa-sm"></i> -->
+                                                比較
+                                            </button>
 
-
+                                        </div>
+                                    </div>
                                 </div>
                             </div>
-
+                            <!-- </div> -->
                         </div>
-
                     </div>
                 </div>
                 <!-- /.container-fluid -->
@@ -403,24 +447,29 @@
             </div>
 
             <!-- <p class="font-weight-bold">標題位置:</p>  -->
-            <div class="form-check form-check-inline">
-                <input class="form-check-input" value="0" type="radio" name="inlineRadioOptions" id="inlineRadio1"
-                    value="option1" checked>
-                <label class="form-check-label" for="inlineRadio1">置左</label>
-            </div>
-            <div class="form-check form-check-inline">
-                <input class="form-check-input" value="1" type="radio" name="inlineRadioOptions" id="inlineRadio2"
-                    value="option2">
-                <label class="form-check-label" for="inlineRadio2">置中</label>
+            <div class="mb-2">
+                <div class="form-check form-check-inline">
+                    <input class="form-check-input" value="0" type="radio" name="inlineRadioOptions" id="inlineRadio1"
+                        value="option1" checked>
+                    <label class="form-check-label" for="inlineRadio1">置左</label>
+                </div>
+                <div class="form-check form-check-inline">
+                    <input class="form-check-input" value="1" type="radio" name="inlineRadioOptions" id="inlineRadio2"
+                        value="option2">
+                    <label class="form-check-label" for="inlineRadio2">置中</label>
+                </div>
+                <div class="form-check form-check-inline">
+                    <input class="form-check-input" value="2" type="radio" name="inlineRadioOptions" id="inlineRadio3"
+                        value="option2">
+                    <label class="form-check-label" for="inlineRadio3">置右</label>
+                </div>
             </div>
-            <div class="form-check form-check-inline">
-                <input class="form-check-input" value="2" type="radio" name="inlineRadioOptions" id="inlineRadio3"
-                    value="option2">
-                <label class="form-check-label" for="inlineRadio3">置右</label>
+            <div id="unit_input">
+                <p class="font-weight-bold">單位:</p>
+                <input type="text" id="unit_data" class="form-control bg-light small mb-3" aria-label="Search2"
+                    aria-describedby="basic-addon2">
             </div>
-            <p class="font-weight-bold">單位:</p>
-            <input type="text" id="unit_data" class="form-control bg-light small mb-3" aria-label="Search2"
-                aria-describedby="basic-addon2">
+
         </form>
 
         <!-- <form class="ml-md-3 mr-md-3 my-2">
@@ -446,6 +495,17 @@
 
             </div>
         </form>
+        <form id="pie_setting" class="ml-md-3 mr-md-3 my-2 chartSetting">
+            <div>
+                <p class="font-weight-bold">字體大小:</p>
+                <label class="d-none" for="table_fontSize">字體大小:</label>
+                <input type="number" value="14" step="1" class="form-control mb-3" id="pie_fontSize" />
+
+                <p class="font-weight-bold">標籤寬度:</p>
+
+                <input type="range" id="PieMaxWidthRange" min="50" max="200" step="10" value="100">
+            </div>
+        </form>
         <form id="table_setting" class="ml-md-3 mr-md-3 my-2 chartSetting">
             <div>
                 <p class="font-weight-bold">圖表字體大小:</p>
@@ -551,9 +611,7 @@
         </form>
     </div>
 
-    <div style="height:300px">
 
-    </div>
 
 
 

+ 353 - 18
js/demo/text-to-chart.js

@@ -36,9 +36,15 @@ var inputField = document.getElementById("keyword_data");
 
 var inputField_compare = document.getElementById("keyword_data_compare");
 
+var compare_box = document.getElementById("compare");
+
+
 
 var sendButton = document.getElementById("send_data");
 
+var send_data_compare = document.getElementById("data_compare");
+
+
 var canvasPng = document.getElementById("textToChart");
 
 var img_box = document.getElementById("img_box");
@@ -64,6 +70,9 @@ var YfontSizeValue = 18;
 
 var TitlefontSizeValue = 32;
 
+var pieFontSize = 14;
+var PieMaxWidth = 100;
+
 
 var chart_bgimg_url = "url(./img/bg06.webp)";
 
@@ -71,11 +80,15 @@ var vocab = [];
 
 var chartDiv = document.getElementById('chartdiv');
 
+var dataFirstValue;
+var dataLastValue;
+
 let cancelToken;
 let source;
 
 $('#chartdiv').hide();
 
+var clickExample = document.getElementById('example_box')
 
 document.addEventListener('DOMContentLoaded', function () {
     axios.get("https://cmm.ai:8080/vocab")
@@ -141,7 +154,7 @@ document.addEventListener('DOMContentLoaded', function () {
                 //     suggestions.style.display = 'none'; // 隱藏建議容器
 
                 // });
-                console.log('queryTerms', queryTerms);
+                // console.log('queryTerms', queryTerms);
 
                 // console.log('filteredVocab', filteredVocab);
 
@@ -243,7 +256,7 @@ document.addEventListener('DOMContentLoaded', function () {
                 //     suggestions.style.display = 'none'; // 隱藏建議容器
 
                 // });
-                console.log('queryTerms', queryTerms);
+                // console.log('queryTerms', queryTerms);
 
                 // console.log('filteredVocab', filteredVocab);
 
@@ -318,6 +331,7 @@ function sendButtonClickHandler() {
     // inputField.value = "";
     console.log(inputField.value);
     var input_text_value = inputField.value;
+    compare_box.style.display = "none";
     $('#chartdiv').hide();
     sidebar.classList.remove('show');
     sidebar.classList.add('hidden');
@@ -329,6 +343,135 @@ sendButton.addEventListener("click", function () {
 
     sendButtonClickHandler();
     inputField.value = ''
+    chartTypeBtn.style.display = "none";
+});
+
+let labels2 = [];
+let data2 = [];
+
+
+
+send_data_compare.addEventListener("click", function () {
+
+
+
+    console.log('比較', inputField_compare.value);
+    const stockName = inputField_compare.value;
+    axios
+        .get(`https://cmm.ai:8080/get_data_from_date?start_date=${dataFirstValue}&end_date=${dataLastValue}&stock_name=${inputField_compare.value}`)
+        .then((response) => {
+            console.log(response);
+            var compare_data = response.data.data;
+            labels2 = [];  // Clear previous labels
+            data2 = [];  // Clear previous data
+
+            // console.log('比較送出後', chartType)
+
+            if (chartType === 'line') {
+                const colors = [
+                    'rgba(130, 163, 63, 1)',
+                    'rgba(47, 72, 123, 1)',
+                    '#df8c49',
+                    '#72598f',
+                    '#489fb6',
+                    '#99b0d5'
+                ];
+
+                let colorIndex = 0;
+
+                for (var i = 0; i < compare_data.length; i++) {
+                    var item = compare_data[i];
+                    // 遍历当前项的属性
+                    for (var key in item) {
+                        // 如果属性名不在 labels 数组中,并且属性值不是对象,则将属性名添加到 labels 数组中
+
+                        if (typeof item[key] === 'string') {
+                            labels2.push(item[key]);
+                        }
+                        // 如果属性值是数值类型,则将其添加到 data 数组中
+                        if (typeof item[key] === 'number') {
+                            data2.push(item[key]);
+                        }
+                    }
+                }
+
+
+                function getRandomColor() {
+                    const randomIndex = Math.floor(Math.random() * colors.length);
+                    const selectedColor = colors[randomIndex];
+                    colors.splice(randomIndex, 1); // 从数组中移除已选颜色
+                    return selectedColor;
+                }
+
+
+                const normalize = (prices) => {
+                    const initialPrice = prices[0];
+                    return prices.map(price => (price - initialPrice) / initialPrice * 100);
+                };
+
+                const stock2Normalized = normalize(data2);
+
+                const stock1Normalized = normalize(data);
+                const color = getRandomColor();
+
+                const newDataset = {
+                    label: stockName,
+                    backgroundColor: colors,
+                    pointRadius: 0,
+                    pointHoverRadius: 0,
+                    borderColor: colors,
+                    data: stock2Normalized,
+                    fill: false
+                };
+
+
+
+                colorIndex = (colorIndex + 1) % colors.length;
+
+                myChart.data.datasets.push(newDataset);
+
+
+
+                myChart.data.datasets[0].data = stock1Normalized;
+
+
+
+
+                console.log('多筆資料', myChart.data.datasets);
+
+
+
+
+                // console.log('比較', myChart.options.plugins.legend);
+
+                myChart.options.plugins.legend.display = true;
+
+                // myChart.defaults.global.legend = {
+                //     display: true,
+                //     position: 'top', // 默认图例位置为顶部
+                //     labels: {
+                //         fontColor: 'rgb(255, 99, 132)', // 默认图例标签颜色
+                //         fontSize: 14 // 默认图例标签字体大小
+                //     }
+                // };
+
+                myChart.update();
+
+                inputField_compare.value = '';
+                unitInput.value = '%';
+                unit_value.textContent = '單位:' + '%'
+            } else if (chartType === 'bar') {
+
+            }
+
+
+
+
+        })
+        .catch((error) =>
+            console.log(error)
+        );
+
 });
 
 // sendButton.addEventListener("click", function () {
@@ -444,14 +587,33 @@ function generateChart(dataArray) {
 
             if (typeof item[key] === 'string') {
                 labels.push(item[key]);
+
+            } else {
+
+                if (key === 'x') {
+                    labels.push(String(item[key]));
+                }
+
             }
-            // 如果属性值是数值类型,则将其添加到 data 数组中
-            if (typeof item[key] === 'number') {
+
+            if (key === 'y') {
                 data.push(item[key]);
             }
+            // 如果属性值是数值类型,则将其添加到 data 数组中
+            // if (typeof item[key] === 'number') {
+            //     data.push(item[key]);
+            // }
         }
     }
     console.log(data);
+    dataFirstValue = labels[0];
+    dataLastValue = labels[labels.length - 1]
+
+    console.log('dataFirstValue', dataFirstValue);
+
+    console.log('dataLastValue', dataLastValue);
+
+
     if (myChart) {
         console.log('已存在')
         myChart.destroy();
@@ -498,7 +660,9 @@ function extractAndGenerateChart(dataArray) {
 }
 
 // 圓餅圖
-function generatePieChart(dataArray) {
+function generatePieChart(dataArray, pieFontSize, PieMaxWidth) {
+    compare_box.style.display = "none";
+
     $('#chartdiv').show();
     bgImgelement.style.backgroundImage = chart_bgimg_url;
     // chartDiv.style.width = "100%"
@@ -522,20 +686,34 @@ function generatePieChart(dataArray) {
 
     // Configure labels
     pieSeries.labels.template.wrap = true;
-    pieSeries.labels.template.maxWidth = 100;
+    console.log('PieMaxWidth', PieMaxWidth);
+    pieSeries.labels.template.maxWidth = PieMaxWidth;
     pieSeries.labels.template.truncate = false;
     pieSeries.labels.template.fontSize = 14;
 
+    if (typeof PieMaxWidth === 'string') {
+        console.log('The variable is a string.');
+    } else {
+        console.log('The variable is a number.');
+    }
+
     // Configure label text to wrap and show percentages
+    // pieSeries.labels.template.adapter.add("textOutput", function (text, target) {
+    //     if (target.dataItem && target.dataItem.values.value.percent) {
+    //         return "[font-size: 14px]" + target.dataItem.category + ": " + target.dataItem.values.value.percent.toFixed(1) + "%";
+    //     }
+    //     return text;
+    // });
+
+
     pieSeries.labels.template.adapter.add("textOutput", function (text, target) {
         if (target.dataItem && target.dataItem.values.value.percent) {
-            return "[font-size: 14px]" + target.dataItem.category + ": " + target.dataItem.values.value.percent.toFixed(1) + "%";
+            return "[font-size: " + pieFontSize + "px]" + target.dataItem.category + ": " + target.dataItem.values.value.percent.toFixed(1) + "%";
         }
         return text;
     });
 
 
-
     pieSeries.colors.list = [
         am4core.color('rgb(171, 51, 49)'),
         am4core.color('rgb(34, 83, 149)'),
@@ -563,6 +741,10 @@ function generatePieChart(dataArray) {
 
     // console.log('調位置')
     downloadButton.style.display = "inline-block";
+    chartTypeBtn.style.display = "inline-block";
+
+
+
 }
 
 // var colorEven='#288D97';
@@ -596,6 +778,12 @@ function adjustColorBrightness(color, amount) {
 }
 // 柱狀圖
 function generateBarChart(key, dataArray) {
+
+    console.log('generateBarChart', dataArray)
+    chartTypeBtn.style.display = "inline-block";
+    compare_box.style.display = "none";
+
+
     $('#chartdiv').show();
     // var colorEven = document.getElementById('colorEven').value;
     // var colorOdd = document.getElementById('colorOdd').value;
@@ -627,7 +815,7 @@ function generateBarChart(key, dataArray) {
     // Create chart instance
     var chart = am4core.create("chartdiv", am4charts.XYChart3D);
 
-    console.log('判斷資料', dataArray);
+
 
     chart.data = dataArray;
 
@@ -651,7 +839,9 @@ function generateBarChart(key, dataArray) {
     label.wrap = true;
     if (dataArray.length > 5) {
         console.log('資料長度5')
-        label.maxWidth = 50;
+        label.maxWidth = 60;
+    } else if (dataArray.length < 7) {
+        label.maxWidth = 70;
     } else {
         label.maxWidth = 100;
         console.log('資料長度<5')
@@ -734,6 +924,9 @@ function generateBarChart(key, dataArray) {
     lineSeries.data = bottomData;
 
     downloadButton.style.display = "inline-block";
+    chartTypeBtn.style.display = "inline-block";
+    chartTypeBtn.style.opacity = "1";
+
 
     // 底部線條
     // let rectElements = document.querySelectorAll("rect");
@@ -761,7 +954,57 @@ function generateBarChart(key, dataArray) {
     // end am4core.ready()
 }
 
+function handleClick(element) {
+    const Clickvalue = element.dataset.value;
+    console.log(Clickvalue); // 123
+
+    get_data(Clickvalue);
+
+
+}
+
+// 圖表類型
+var chartTypeBtn = document.getElementById("chartType");
+
+chartTypeBtn.addEventListener('change', function () {
+    const selectedValue = this.value;
+    console.log('選擇的圖表類型:', selectedValue);
+
+    // 在此处添加处理选定图表类型的代码
+    if (selectedValue === 'line') {
+        // 处理折线图
+        console.log('處理折線圖', dataArray);
+
+        $('#chartdiv').hide();
+        chartType = 'line';
+        if (myChart) {
+            data = [];
+            labels = [];
+            myChart.destroy();
+        }
 
+        generateChart(dataArray);
+
+    } else if (selectedValue === 'bar') {
+        chartType = 'bar';
+
+        $('#textToChart').hide();
+        // 处理柱状图
+        console.log('處理柱狀圖', dataArray);
+
+        extractAndGenerateChart(dataArray);
+    } else if (selectedValue === 'doughnut') {
+        chartType = 'doughnut';
+
+        console.log('處理圓餅圖', dataArray);
+        unit_value.textContent = "";
+        $('#textToChart').hide();
+
+        generatePieChart(dataArray, pieFontSize, PieMaxWidth)
+        // 处理圆饼图
+
+    }
+});
 
 
 
@@ -1082,6 +1325,13 @@ function createTable(dataArray, unit, Label_dependent_variable, Label_independen
 
     downloadButton.style.display = "inline-block";
 
+    chartTypeBtn.style.display = "inline-block";
+
+
+    chartTypeBtn.style.opacity = "0";
+
+
+
 }
 
 function getDatalabelsConfig(dataLength) {
@@ -1105,20 +1355,42 @@ function getDatalabelsConfig(dataLength) {
     }
 }
 
+var pointRadiusValue = 0;
+var pointHoverRadiusValue = 0;
 
 
 // 版型一折線圖
 // // 创建 Chart.js 图表
 function createChart(chartType, data, labels) {
+
     $('#textToChart').show();
     canvasPng.style.maxWidth = '';
     canvasPng.style.maxHeight = '';
 
+    console.log('繪製圖表', data, labels);
+
+
+
+    if (data.length < 15) {
+        pointRadiusValue = 5;
+        pointHoverRadiusValue = 8;
+
+        togglePoints.checked = true;
+    }
+
 
 
-    const datalabelsConfig = data.length <= 10 ? {
+    const datalabelsConfig = data.length <= 15 ? {
         formatter: function (value, context) {
+            // if (context.dataIndex === 0) {
+            //     return '';
+            // }
+            // if (typeof value === 'number' && value.toString().includes('.')) {
+            //     value = value.toFixed(4);
+            // }
+            // return value;
             return value;
+
         },
         textStrokeColor: '#fff',
         textStrokeWidth: 5,
@@ -1130,6 +1402,8 @@ function createChart(chartType, data, labels) {
         align: 'top'
     } : null;
 
+
+
     ctx = document.getElementById("textToChart");
 
     myChart = new Chart(ctx, {
@@ -1137,14 +1411,15 @@ function createChart(chartType, data, labels) {
         data: {
             labels: labels,
             datasets: [{
+                label: stocknumber,
                 strokeColor: "rgba(220,220,220,1)",
                 StrokeWidth: 5,
                 data: data,
                 borderWidth: borderWidthValue,
-                pointRadius: 0,
+                pointRadius: pointRadiusValue,
                 pointBorderColor: '#fff',
                 pointBorderWidth: 3,
-                pointHoverRadius: 0,
+                pointHoverRadius: pointHoverRadiusValue,
                 fill: false,
                 backgroundColor: chartColor,
                 borderColor: chartColor,
@@ -1153,6 +1428,7 @@ function createChart(chartType, data, labels) {
             }]
         },
         options: {
+
             // responsive: true, // 啟用響應式
             maintainAspectRatio: false,
 
@@ -1196,6 +1472,7 @@ function createChart(chartType, data, labels) {
                 //     align: 'end',
                 // } : null,
                 customLabels: null,
+
                 legend: {
                     display: false,
                 },
@@ -1304,6 +1581,7 @@ function createChart(chartType, data, labels) {
         },
     });
 
+    console.log('第一次', myChart.options.legend)
 
     // 注册 afterDraw 事件
     // Chart.register({
@@ -1355,6 +1633,15 @@ function createChart(chartType, data, labels) {
     chartWhitelement.style.background = "rgba(255,255,255,0.5)";
 
     downloadButton.style.display = "inline-block";
+    chartTypeBtn.style.display = "inline-block";
+    chartTypeBtn.style.opacity = "1";
+
+
+    compare_box.style.display = "flex";
+
+
+
+
 }
 
 // createChart(chartType);
@@ -1403,12 +1690,43 @@ fontSizeInput.addEventListener('input', function () {
     }
 });
 
+// 圓餅圖字體
+var pieFontSizeInput = document.getElementById('pie_fontSize');
+
+// 添加事件监听器
+pieFontSizeInput.addEventListener('input', function () {
+    // 获取输入框的值
+    pieFontSize = pieFontSizeInput.value;
+
+
+    console.log('圓餅圖字體', pieFontSize);
+
+    if (pieFontSize) {
+        generatePieChart(dataArray, pieFontSize, PieMaxWidth);
+    } else {
+        alert("Please enter a valid font size.");
+    }
+
+    // 如果表格存在,则调整其字体大小
+    // if (dynamicTable) {
+    //     dynamicTable.style.fontSize = fontSize + 'px';
+    // }
+});
+
+
+document.getElementById('PieMaxWidthRange').addEventListener('input', function () {
+    PieMaxWidth = Number(document.getElementById('PieMaxWidthRange').value);
+    console.log('圓餅圖', PieMaxWidth)
+    generatePieChart(dataArray, pieFontSize, PieMaxWidth);
+});
+
+
 // 是否顯示point
 
 var togglePoints = document.getElementById('togglePoints');
 
 togglePoints.addEventListener('change', function () {
-    console.log('checked')
+    console.log('checked', "change")
     if (this.checked) {
         myChart.data.datasets[0].pointRadius = 5;
         myChart.data.datasets[0].pointHoverRadius = 8;
@@ -1438,7 +1756,7 @@ unitInput.addEventListener('input', function () {
             span.textContent = this.value;
         });
     } else {
-        unit_value.textContent = '單位:' + this.value
+        unit_value.textContent = '單位:' + this.value;
 
     }
 
@@ -1623,6 +1941,7 @@ document.addEventListener("DOMContentLoaded", function () {
 
             if (bgImgUrl === './img/bg07.webp') {
                 chartTitle.style.color = "#ffff";
+                chartTitle.style.padding = '0px'
             } else {
                 chartTitle.style.color = "#1c2d6d";
             }
@@ -1682,13 +2001,14 @@ TitlefontSize.addEventListener('input', function () {
 // 標題字體顏色
 
 
-
+var stocknumber;
 // ==========================
 
 
 let labelDependent = ""; // 圖表左側 Label
 
 function get_data(input_text_value) {
+    clickExample.style.display = 'none'
     // 重新创建取消令牌和源
     cancelToken = axios.CancelToken;
     source = cancelToken.source();
@@ -1762,6 +2082,10 @@ function get_data(input_text_value) {
 
                 var Label_independent_variable = response.data.chart_info.Label_independent_variable;
 
+                stocknumber = response.data.chart_info.args;
+
+                chartTypeBtn.value = chartType;
+
 
                 unit_data.value = response.data.chart_info.Unit_of_dependent_variable;
                 if (response.data.chart_info.Unit_of_dependent_variable == "") {
@@ -1788,7 +2112,7 @@ function get_data(input_text_value) {
                     unit_value.textContent = "";
                     $('#textToChart').hide();
 
-                    generatePieChart(dataArray)
+                    generatePieChart(dataArray, pieFontSize, PieMaxWidth)
                 } else {
                     $('#chartdiv').hide();
                     generateChart(dataArray);
@@ -1855,7 +2179,8 @@ $(document).ready(function () {
 
 
 function resizeChart() {
-    if (myChart) {
+    console.log(myChart)
+    if (myChart != null) {
         myChart.resize();
     }
 }
@@ -1891,6 +2216,8 @@ var table_setting = document.getElementById('table_setting');
 
 var chart_category = document.getElementById('chart_category');
 
+var pie_setting = document.getElementById('pie_setting');
+
 
 // 获取 chartDiv 元素
 
@@ -1911,6 +2238,8 @@ setting_button.addEventListener('click', () => {
         lineChartSetting.style.display = 'none';
         table_setting.style.display = 'block';
         chart_category.style.display = 'none';
+        pie_setting.style.display = 'none';
+
 
     } else if (chartType === "bar") {
         console.log('柱狀圖')
@@ -1919,6 +2248,8 @@ setting_button.addEventListener('click', () => {
         barChartSetting.style.display = 'block';
         lineChartSetting.style.display = 'none';
         table_setting.style.display = 'none';
+        pie_setting.style.display = 'none';
+
 
 
     } else if (chartType === "doughnut") {
@@ -1927,8 +2258,10 @@ setting_button.addEventListener('click', () => {
         sidebar.classList.toggle('hidden');
         barChartSetting.style.display = 'none';
         lineChartSetting.style.display = 'none';
+        pie_setting.style.display = 'block';
         table_setting.style.display = 'none';
         chart_category.style.display = 'none';
+        document.getElementById('unit_input').style.display = 'none';
 
     } else {
         sidebar.classList.toggle('show');
@@ -1936,6 +2269,8 @@ setting_button.addEventListener('click', () => {
         table_setting.style.display = 'none';
         barChartSetting.style.display = 'none';
         lineChartSetting.style.display = 'block';
+        pie_setting.style.display = 'none';
+
     }
 
 });