You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by "echarts-bot[bot] (via GitHub)" <gi...@apache.org> on 2023/05/12 05:47:11 UTC

[GitHub] [echarts] echarts-bot[bot] commented on issue #18617: 怎么延长线性回归 线?

echarts-bot[bot] commented on issue #18617:
URL: https://github.com/apache/echarts/issues/18617#issuecomment-1545200435

   @fff21 It seems you are not using English, I've helped translate the content automatically. To make your issue understood by more people and get helped, we'd like to suggest using English next time. 🤗
   <details><summary><b>TRANSLATED</b></summary><br>
   
   **TITLE**
   
   How to extend the linear regression line?
   
   **BODY**
   
   ### What problem does this feature solve?
   
   ### What problem does this feature solve?
   
   The axis value is large, and when the data is small, it is squeezed in the middle. How can the two ends of the line touch the bottom (as shown in the figure)
   Hope to get a solution(ノ゚▽゚)ノ
   `getEchart() {
         this.$echarts.registerTransform(ecStat.transform.regression);
   
         let myChart4 = this.$echarts.init(document.getElementById("charts"));
   
         let mp = {
           symbol: 'arrow', symbolSize: 5, symbolRotate: -90,
           label: {show: true, position: 'left', formatter: '{c}'},
           data: [
             {yAxis: 5, xAxis: 10, value: '5.00'},
             {yAxis: 40, xAxis: 10, value: '40.00'}
           ]
         }
   
         let option = {
           dataset: [
             {
               source: [
                 [90, 12.988],
                 [109,30],
                 [283, 42.5],
                 [327, 56.0],
                 [452, 74.4],
                 [440, 88.2],
               ],
             },
             {
               transform: {
                 type: 'ecStat: regression'
               }
             },
             {
               id: 2,
               source: [
                 [173, 21],
                 [221,34],
                 [456,41],
                 [466,62],
                 [744,89]
               ]
             },
             {
               fromDatasetId: 2,
               transform: {
                 type: 'ecStat: regression'
               }
             },
             {
               id: 3,
               source: [
                 [344,21],
                 [821,36],
                 [856,51],
                 [879,67],
                 [958,81]
               ]
             },
             {
               fromDatasetId: 3,
               transform: {
                 type: 'ecStat: regression'
               }
             }
           ],
   
           legend: {
             bottom: 5
           },
           tooltip: {
             trigger: 'axis',
             axisPointer: {
               type: 'cross'
             }
           },
           xAxis: {
             type: 'log',
             min: 10, max: 1000000,
             splitLine: {
               lineStyle: {
                 type: 'dashed'
               }
             },
             axisLabel: {
               formatter: function (value) {
                 if (Math. abs(value) > 1000) {
                   if (value == 0) {
                     return "0";
                     // Check if it has been converted to scientific notation
                   } else if ((value + ''). indexOf('e') > 0) {
                     return (value + '').replace(/e/, "E");
                   } else {
                     var res = value. toString();
                     var numN1 = 0;
                     var numN2 = 1;
                     var num1 = 0;
                     var num2 = 0;
                     var t1 = 1;
                     // How many digits are counted before and after the decimal point
                     for (var k = 0; k < res. length; k++) {
                       if (res[k] == ".")
                         t1 = 0;
                       if (t1)
                         num1++;
                       else
                         num2++;
                     }
                     // Both are converted to scientific notation
                     if (Math. abs(value) < 1) {
                       // Start counting with one decimal place
                       for (var i = 2; i < res. length; i++) {
                         if (res[i] == "0") {
                           numN2++; //Record the negative index value of 10 (the default value starts from 1)
                         } else if (res[i] == ".")
                           continue;
                         else
                           break;
                       }
                       let v = parseFloat(value);
                       // 10 to the numN2 power
                       v = v * Math.pow(10, numN2);
                       v = v.toFixed(1); // rounded to keep only one decimal place
                       return v.toString() + "e-" + numN2;
                     } else if (num1 > 1) {
                       numN1 = num1 - 1;
                       let v = parseFloat(value);
                       v = v / Math.pow(10, numN1);
                       if (num2 > 1) {
                         v = v.toFixed(1);
                       }
                       return v.toString() + "e" + `+`+ numN1;
                     }
                   }
                 } else {
                   return value;
                 }
               }
             }
           },
           yAxis: {
             type: 'log',
             min: 1.0, max: 99.90,
             splitLine: {
               lineStyle: {
                 type: 'dashed'
               }
             }
           },
           series: [
             {
               symbol: 'triangle',
               name: 'scatter',
               type: 'scatter',
               datasetIndex: 0
             },
             {
               name: 'line',
               type: 'line',
               datasetIndex: 1,
               symbol: 'circle',
               encode: { label: 2, tooltip: 1 }
             },
             {
               // Scatter shape setting symbol: 'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow'
               symbol:'roundRect',
               name: 'scatter2',
               type: 'scatter',
               datasetIndex: 2
             },
             {
               name: 'line2',
               type: 'line',
               smooth: true,
               datasetIndex: 3,
               symbol: 'circle',
               encode: { label: 2, tooltip: 1 }
             },
             {
               name: 'scatter3',
               type: 'scatter',
               datasetIndex: 4
             },
             {
               name: 'line3',
               type: 'line',
               smooth: true,
               datasetIndex: 5,
               symbol: 'circle',
               encode: { label: 2, tooltip: 1 }
             },
             {
               type: 'scatter',
               datasetIndex: 6,
               itemStyle: {
                 normal: {
                   color: '#a80000', //Change the color of the polyline point
                   lineStyle: {
                     color: '#a80000' //Change the polyline color
                   }
                 }
               },
               markPoint: mp,
               markLine: {
                 symbol: ['none','none'],
                 label: {position:'start'},
                 data: [{yAxis: 63.21}]
               }
             },
           ]
         };
         // Display the chart using the specified configuration items and data.
         myChart4.setOption(option);
       },`
   
   ### What does the proposed API look like?
   
   ![Snipaste_2023-05-12_13-34-26](https://github.com/apache/echarts/assets/130143783/cc6e026c-9226-4ab0-b9b1-77180e45a52f)
   This is the desired effect
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org