简体   繁体   English

在googleVis图表中将特殊字符转换为utf-8

[英]Converting special characters to utf-8 in googleVis charts

In this related question an html (or php) file is produced and a googleVis chart can then be loaded into a joomla (for example) article, using something like that 在这个相关问题中,产生了一个html(或php)文件,然后可以使用类似的方法将googleVis图表加载到joomla(例如)文章中

{source}
<?php
  include("tmp.php");
?>
{/source}

The column name with the subject to be analysed must be passed to the gvisMotionChart's idvar property. 带有要分析的主题的列名称必须传递给gvisMotionChart的 idvar属性。 In my case this column includes values in greek and they appear as squares on the chart. 在我的情况下,此列包含希腊值,它们在图表上显示为正方形。 I thought I could use iconv to convert those strings to utf-8 character encoding. 我以为可以用iconv将那些字符串转换为utf-8字符编码。 However, I haven't been able to use it successfully. 但是,我无法成功使用它。

Could you help me have those labels shown properly? 您能帮我正确显示那些标签吗?

EDIT 编辑

I found out that if I replace the strings including greek characters (the double quotes included) as follows, then it works 我发现,如果我按以下方式替换包含希腊字符(包括双引号)的字符串,则它可以工作

Replace 更换

"greekcharacters"

with

<?php echo '"' . iconv('greek','utf-8','greekcharacters') . '"'; ?>

How can I do this globally, within R? 如何在R中全局执行此操作?

I think I have found it. 我想我已经找到了。 Instead of 代替

cat(M$html$chart, file="tmp.php")

use 采用

cat(M$html$chart, file = (con <- file("tmp.php", "w", encoding="UTF-8"))); close(con)

I found it at the end of the connections help file 我在连接帮助文件的末尾找到了它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM