如何在脚本中显示数据?

发布于 2025-01-17 08:10:26 字数 3980 浏览 0 评论 0原文

这是我当前的代码,问题是我不知道如何返回值,我不知道为什么我的函数的作者未定义,我想要的是从查询中获取数据并将其传递给 const reportChart,请帮忙,谢谢

这是我的完整代码吗?我错过了什么吗?

<script>
    async function myFunction() {
       var author = ("SELECT name FROM People", 10, (value)=>{
              console.log(value)//please see the data below
              return value;
        })
      return author; //undefined
    }
    myFunction().then(function(value){reportChart(value);})
    const reportChart = (value) => {
      console.log("inside chart: ",value) //The value of value is undefined
         $("#chart").kendoChart({
            title: {
                text: "School Library"
            },
            legend: {
                visible: false
            },
            seriesDefaults: {
                type: "bar"
            },
            series: [{
                name: "Total Visits",
                data: [1, 2, 3]
            }, {
                name: "Total Visits",
                data: [1, 2, 3]
            }],
            valueAxis: {
                max: 10,
                line: {
                    visible: false
                },
                minorGridLines: {
                    visible: true
                },
                labels: {
                    rotation: "auto"
                }
            },
             categoryAxis: {
                categories: [value],//undefined
                majorGridLines: {
                    visible: false
                }
              }, 
            tooltip: {
                visible: true,
                template: "#= series.name #: #= value #"
            }
        });
       
    }

    $(document).ready(reportChart);
    $(document).bind("kendo:skinChange", reportChart);
</script>

console.log(value) 的结果

0: ['马克'] 1: ['约瑟夫'] 2: ['卢娜'] 3: ['尤诺']

更新

我删除了一些代码并替换了这个

<script>
   let myPromise = new Promise(function(myResolve, myReject){
      var author = ("SELECT name FROM People", 10, (value) => {
         return myResolve(value)
       });
   })
   myPromise.then(
    function(value) {reportChart(value);},
    function(error) {reportChart(error);}
  );
    function reportChart (value, index) {
      console.log(index, value.length)
      var i = 0
      var author= []
      for(i=0; i<=value.length; i++)
        {
          author[i] = value[i]
        }
         $("#chart").kendoChart({
            title: {
                text: "Library"
            },
            legend: {
                visible: false
            },
            seriesDefaults: {
                type: "bar"
            },
            series: [{
                name: "Total Visits",
                data: [1,2,3,4]
            }, {
                name: "Total Visits",
                data: [4,5,6,7]
            }],
            valueAxis: {
                max: 10,
                line: {
                    visible: false
                },
                minorGridLines: {
                    visible: true
                },
                labels: {
                    rotation: "auto"
                }
            },
             categoryAxis: {
                categories: [author],
                majorGridLines: {
                    visible: false
                }
              }, 
            tooltip: {
                visible: true,
                template: "#= series.name #: #= value #"
            }
        });
       
    }
    $(document).ready(reportChart);
    $(document).bind("kendo:skinChange", reportChart);
</script>

**

这就是现在的结果

在此处输入图像描述

我想要的是,请帮忙

在此处输入图像描述

This is my current code, the problem is I dont know how to return the value, i dont know why the author from my function are undefined, what i want is to get the data from my query and pass it to the const reportChart, please help, thanks

this is my full code? did i miss something?

<script>
    async function myFunction() {
       var author = ("SELECT name FROM People", 10, (value)=>{
              console.log(value)//please see the data below
              return value;
        })
      return author; //undefined
    }
    myFunction().then(function(value){reportChart(value);})
    const reportChart = (value) => {
      console.log("inside chart: ",value) //The value of value is undefined
         $("#chart").kendoChart({
            title: {
                text: "School Library"
            },
            legend: {
                visible: false
            },
            seriesDefaults: {
                type: "bar"
            },
            series: [{
                name: "Total Visits",
                data: [1, 2, 3]
            }, {
                name: "Total Visits",
                data: [1, 2, 3]
            }],
            valueAxis: {
                max: 10,
                line: {
                    visible: false
                },
                minorGridLines: {
                    visible: true
                },
                labels: {
                    rotation: "auto"
                }
            },
             categoryAxis: {
                categories: [value],//undefined
                majorGridLines: {
                    visible: false
                }
              }, 
            tooltip: {
                visible: true,
                template: "#= series.name #: #= value #"
            }
        });
       
    }

    $(document).ready(reportChart);
    $(document).bind("kendo:skinChange", reportChart);
</script>

the result of console.log(value)

0: ['Mark'] 1: ['Joseph'] 2: ['Luna'] 3: ['Yuno']

Update

I remove some code and replace this

<script>
   let myPromise = new Promise(function(myResolve, myReject){
      var author = ("SELECT name FROM People", 10, (value) => {
         return myResolve(value)
       });
   })
   myPromise.then(
    function(value) {reportChart(value);},
    function(error) {reportChart(error);}
  );
    function reportChart (value, index) {
      console.log(index, value.length)
      var i = 0
      var author= []
      for(i=0; i<=value.length; i++)
        {
          author[i] = value[i]
        }
         $("#chart").kendoChart({
            title: {
                text: "Library"
            },
            legend: {
                visible: false
            },
            seriesDefaults: {
                type: "bar"
            },
            series: [{
                name: "Total Visits",
                data: [1,2,3,4]
            }, {
                name: "Total Visits",
                data: [4,5,6,7]
            }],
            valueAxis: {
                max: 10,
                line: {
                    visible: false
                },
                minorGridLines: {
                    visible: true
                },
                labels: {
                    rotation: "auto"
                }
            },
             categoryAxis: {
                categories: [author],
                majorGridLines: {
                    visible: false
                }
              }, 
            tooltip: {
                visible: true,
                template: "#= series.name #: #= value #"
            }
        });
       
    }
    $(document).ready(reportChart);
    $(document).bind("kendo:skinChange", reportChart);
</script>

**

this is now the result

enter image description here

What I want is, please help

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温馨耳语 2025-01-24 08:10:26

这里:listsOfPeople = value,我想您想要的是listsOfPeople.push(value);


您的代码应类似于 varauthor = doQuery("SELECT name FROM People"....

可能的问题:

  • doQuery() 意外更改 listsOfPeople 或者
  • 只是变量名称上的一些拼写错误,
  • 您混合使用了 listsOfPeoplelistsOfAuthor

Here: listsOfPeople = value, I guess what you would like to to is listsOfPeople.push(value); instead?


Your code should be like var author = doQuery("SELECT name FROM People"....

Possible issues:

  • doQuery() changes listsOfPeople unexpectedly.
  • Just some typo mistake on your variable name.
  • Or you mixed the use of listsOfPeople and listsOfAuthor.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文