Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JS值名称及其';s值_Javascript_Php_Highcharts - Fatal编程技术网

Javascript JS值名称及其';s值

Javascript JS值名称及其';s值,javascript,php,highcharts,Javascript,Php,Highcharts,我想画图表,我使用highchars.js,我可以从php脚本中获取数据,所以我在phpmonth=[“June”,“July”,]之后有类似的内容,我需要将它放在highchart中 $(function () { $('#container').highcharts({ chart: { type: 'column' xAxis: { categories : month }, ...

我想画图表,我使用highchars.js,我可以从php脚本中获取数据,所以我在php
month=[“June”,“July”,]
之后有类似的内容,我需要将它放在highchart中

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'column'
        xAxis: {
            categories : month
        },

...
    });
但我看到的是变量的名称,而不是它的值,是否可以用它的值替换变量的名称。 我想要这样的东西

var month=["June","July",];
    $(function () {
        $('#container').highcharts({
            chart: {
                type: 'column'
            xAxis: {
                categories : ["June","July"]
            },

    ...
        });

只需使用该变量:

var month=["June","July",];
$(function () {
    $('#container').highcharts({
        chart: {
            type: 'column'
        xAxis: {
            categories : month
        },

...
    });
注意:删除数组末尾的多余逗号。

尝试以下操作:

var month=["June","July"];
$(function () {
    $('#container').highcharts({
        chart: {
            type: 'column'
        xAxis: {
            categories : month
        },

...
    });
为了去掉尾随的“,”应该在PHP代码中将变量的最后一个字符替换为substr,然后再将其输出到JS变量中

因此,如果您的PHP代码有:

$month = "[";
while(LoopConditionForTwelveMonthNames) {
    $month .= '"' . $MonthName . '",';
}
$month = substr($month, 0, strlen($month)-1);
$month .= "]";

然后您可以修复它,这里是一个可以输出适当javascript的示例
highchart.php
脚本

<?php
    $month = array("June", "July");
?>
$(function () {
    $('#container').highcharts({
        chart: {
            type: 'column'
            xAxis: {
                categories : <?php echo json_encode($month); ?>
            }
   });

$(函数(){
$(“#容器”)。高图({
图表:{
类型:“列”
xAxis:{
类别:
}
});

您能举例说明您想做什么吗?在您的案例中,类别将为[“六月”、“七月”,]…我希望类别必须等于变量月,如果我这样做
categories:month
它将不起作用,这是您在问题中的两个组合选项..现场演示:如果您不知道如何从PHP获取变量,请参阅Mohammad的答案。