在谷歌饼图中使用php变量(Use php variable in google pie chart)
我想在Google图表中使用我的PHP变量,但图表无法读取我的PHP标记。 正如您可以看到下面的代码,我将PHP变量放在脚本中。 (我在代码顶部定义的PHP变量,结果是正确的)。 我的代码出了什么问题? 这有什么解决方案吗? 如果需要,请向我询问更多信息。 谢谢。
<script type="text/javascript"> google.charts.load('current', {'packages':['corechart']}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ['Order', 'Amount'], ['Completed', '<?php echo$completed ?>'], ['New', '<?php echo$new ?>'] ]); var options = { title: 'Total Order ' + <?php echo$total; ?> }; var chart = new google.visualization.PieChart(document.getElementById('piechart')); chart.draw(data, options); } </script>
I want to use my PHP variable in Google chart,but the chart couldn't read my PHP tag. As you can see the code below I put my PHP variable in the script. (The PHP variable I have defined at top of the code and the result is correct). What's wrong with my code ? Is there any solution for this ? Do ask me for more information if needed. Thank you.
<script type="text/javascript"> google.charts.load('current', {'packages':['corechart']}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ['Order', 'Amount'], ['Completed', '<?php echo$completed ?>'], ['New', '<?php echo$new ?>'] ]); var options = { title: 'Total Order ' + <?php echo$total; ?> }; var chart = new google.visualization.PieChart(document.getElementById('piechart')); chart.draw(data, options); } </script>
原文:https://stackoverflow.com/questions/40776978
最满意答案
在更多地讨论之后,我意识到Fraser指出了什么 - 这种方法并不总是有效,因为我不能指望GUID可以在新的CMake上运行。 所以我选择了我在CMake邮件列表上看到的建议路径,即自己明确设置GUID值。
所以在每个C ++ / CLI包装器项目的CMakeLists.txt中,我有这样的东西:
# Set a global cache variable for this project GUID # The TestAppNet csproj needs this GUID to properly reference this project set_property(GLOBAL PROPERTY Wrapper_GUID "1897F4D1-E929-444E-9343-00F094113772") get_property(projectGUID GLOBAL PROPERTY Wrapper_GUID) MESSAGE( STATUS "Setting project GUID to: ${projectGUID}") set(Wrapper_GUID_CMAKE "${projectGUID}" CACHE INTERNAL "Project GUID")
在C#项目CMakeLists.txt中,我有这个:
get_property(CMAKE_WRAPPER_GUID GLOBAL PROPERTY Wrapper_GUID) MESSAGE( STATUS "Setting Wrapper GUID to: ${CMAKE_WRAPPER_GUID}" )
...然后将CMAKE_WRAPPER_GUID用作在configure_file命令期间填充的.csproj文件中的变量。
我不确定这是否有效,但似乎有效!
After playing around with this more, I realized what Fraser pointed out - that this method wouldn't always work because I can't expect the GUIDs to be available on a fresh run of CMake. So I went the route that I had seen suggested on the CMake mailing list, which is to explicitly set the GUID values myself.
So in the CMakeLists.txt for each C++/CLI wrapper project, I have something like this:
# Set a global cache variable for this project GUID # The TestAppNet csproj needs this GUID to properly reference this project set_property(GLOBAL PROPERTY Wrapper_GUID "1897F4D1-E929-444E-9343-00F094113772") get_property(projectGUID GLOBAL PROPERTY Wrapper_GUID) MESSAGE( STATUS "Setting project GUID to: ${projectGUID}") set(Wrapper_GUID_CMAKE "${projectGUID}" CACHE INTERNAL "Project GUID")
And in the C# project CMakeLists.txt, I have this:
get_property(CMAKE_WRAPPER_GUID GLOBAL PROPERTY Wrapper_GUID) MESSAGE( STATUS "Setting Wrapper GUID to: ${CMAKE_WRAPPER_GUID}" )
... and then the CMAKE_WRAPPER_GUID is used as a variable in the .csproj file that is populated during the configure_file command.
I'm not sure if this is efficient, but it seems to work!
相关问答
更多-
CMake + GoogleTest(CMake + GoogleTest)[2023-11-06]
这是一个不寻常的情况 大多数项目指定安装规则。 CMake的ExternalProject_Add模块可能是这项工作的最佳工具。 这允许您从项目中下载,配置和构建gtest,然后链接到gtest库。 我已经使用Visual Studio 10和11在Windows上测试了以下CMakeLists.txt,使用GCC 4.8和Clang 3.2在Ubuntu上测试了以下CMakeLists.txt,可能需要为其他平台/编译器进行调整: cmake_minimum_required(VERSION 2.8.7 ... -
CMake如何工作?(How exactly does CMake work?)[2022-06-01]
秘密是你不必了解生成的文件的作用。 CMake在构建系统中引入了大量的复杂性,其中大多数只有在用于构建复杂的软件项目时才有效。 好消息是,CMake做得很好,可以避免很多这样的麻烦:使用源代码外的构建 ,甚至不需要查看生成的文件。 如果你没有这样做(我猜想是这样,因为你写了cmake . ), 请在继续之前检查它们 。 混合构建和源目录对于CMake来说真的很痛苦,而不是系统应该如何使用。 简而言之,而不是 cdcmake . 总是使用 cd 我遇到了同样的挑战,但通过这样运行来解决它: sourceanalyzer -b project_ID -clean 转到构建目录并执行make clean或删除包括Makefile在内的所有内容 通过更改CC和CXX变量来运行cmake: CC =“sourceanalyzer -b project_ID gcc”CXX =“sourceanalyzer -b project_ID g ++”cmake .. 运行make和fortify应该在编译器完成工作时翻译文件。 运行sourceanalyzer ...经过调查,我终于找到了解决方案。 问题不是sub_folders的相对顺序,而是“add_compile_options”的顺序。 要为每个子目录实现不同的编译选项,我必须执行以下操作: #options seen by subfolders if(MINGW) add_compile_options( -Os -Wall -Wextra) endif() add_subdirectory( ProjectRoot/Folder1) add_subdirectory( ProjectRoot/F ...用Maven和JNI进行CMake(CMake with Maven and JNI)[2023-07-16]
create_javah CLASSPATH选项可以指定目录,已经存在的jar文件或使用add_jar命令创建的目标。 只有当jar文件由CMake add_jar命令创建时,才允许它只在构建时存在。 但是,由于create_javah只检查是否存在JAR_FILE属性,因此可以尝试应用以下hack: add_custom_target( JavaProject ALL DEPENDS "${PROJECT_TARGET_DIR}/${PROJECT_JAR}" ) # Add a JAR_ ...我为解决这类问题所做的就是在cmake周围写一个小包装器Makefile。 我把Makefile放在项目根目录下,内容如下: all: cmake cmake: [ -f build/CMakeCache.txt ] && [ "$$(pwd)" != "$$(grep 'CMAKE_HOME_DIRECTORY:INTERNAL' build/CMakeCache.txt | cut -d '=' -f 2)" ] \ && rm -rf build || true mkdir -p b ...在更多地讨论之后,我意识到Fraser指出了什么 - 这种方法并不总是有效,因为我不能指望GUID可以在新的CMake上运行。 所以我选择了我在CMake邮件列表上看到的建议路径,即自己明确设置GUID值。 所以在每个C ++ / CLI包装器项目的CMakeLists.txt中,我有这样的东西: # Set a global cache variable for this project GUID # The TestAppNet csproj needs this GUID to properly re ...是否可以在CMake中更改生成的makefile的名称?(Is it possible to change the name of generated makefile in CMake?)[2022-08-05]
Cmake在工作目录中创建一个构建系统。 因此,创建任何空目录,并从那里运行cmake。 Cmake creates a build system in the working directory. So create any empty directory, and run cmake from there. CMake为其他构建系统生成文件。 这些可以是像Visual Studio或Eclipse这样的IDE的Makefile,Ninja文件或项目文件。 构建文件包含对GCC,Clang或cl.exe等编译器的调用。 如果安装了多个编译器,则可以选择一个。 这三个部分都是独立的。 编译器,构建系统和CMake。 当你有历史时,它更容易理解。 人们用他们的编译器。 随着时间的推移,添加了这么多标志,每次输入它们都很麻烦。 所以把调用放在脚本中。 从那以后,构建系统(Make,Ninja)不断发展。 人们想要支持多 ...为什么我们需要cmake?(Why do we need cmake?)[2022-09-18]
目前在不同平台上用c ++构建东西是一团糟。 有几种不同的构建系统,没有标准的方法来做到这一点。 只提供可视化工作室解决方案,不会帮助在linux或mac上编译。 如果为linux或mac添加makefile,则需要在解决方案和makefile之间重复配置。 这可能导致大量维护开销。 与新版本相比,makefile并不是一个好的构建工具。 你只有CMake库大多是巧合。 CMake目前是一个受欢迎的选择。 有几种解决方案可以统一构建。 CMake是一种特殊的构建工具。 它可以创建makefile并构建它们, ...相关文章
更多- php匹配问题
- Google TTS(文字转语音)api 2
- Solr PHP support
- PHP中的替代语法
- solr安装以及php调用
- PHP简介
- pychseg - A Python Chinese Segment Project - Google Project Hosting
- PHP生成带LOGO的二维码图像
- 微信公众平台Php版php开发(转)
- 关于PHP爬虫和Android定位的初步设想
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)