Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.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 在smarty chartjs中显示json格式的数据 {literal} var ctx=document.getElementById('MyGlacierMarsChart').getContext('2d'); var图表=新图表(ctx{ //我们要创建的图表类型 键入:“行”, //我们的数据集的数据 数据:{ 标签:[{/literal} {foreach from=$glaciermass item=年份名称=glaciermassloop} {if$smarty.foreach.glaciermassloop.last} “{$year.year}” {else} “{$year.year}”, {/if} {/foreach} {literal}], 数据集:[{ 标签:“平均冰川质量水平”, 数据:[{/literal} {foreach from=$glaciermass item=年份名称=glaciermassloop} {if$smarty.foreach.glaciermassloop.last} “{$year.平均累积质量平衡}” {else} “{$year.平均累积质量平衡}”, {/if} {/foreach} {literal}], 背景颜色:[ "rgba(255,99,132,0.2)",, “rgba(54162235,0.2)”, "rgba(255,206,86,0.2)",, “rgba(751921920.2)”, “rgba(153102255,0.2)”, ‘rgba(255、159、64、0.2)’ ], 边框颜色:[ "rgba(255,99,132,1)",, “rgba(54162235,1)”, "rgba(255,206,86,1)",, "rgba(751921921)",, "rgba(153102255,1)",, ‘rgba(255、159、64、1)’ ], 边框宽度:1 }] }, 选项:{ 比例:{ 雅克斯:[{ 滴答声:{ 建议最大值:0, 建议在:-30, 贝吉纳泽罗:是的 } }] } } }); {/literal}_Javascript_Php_Json_Smarty - Fatal编程技术网

Javascript 在smarty chartjs中显示json格式的数据 {literal} var ctx=document.getElementById('MyGlacierMarsChart').getContext('2d'); var图表=新图表(ctx{ //我们要创建的图表类型 键入:“行”, //我们的数据集的数据 数据:{ 标签:[{/literal} {foreach from=$glaciermass item=年份名称=glaciermassloop} {if$smarty.foreach.glaciermassloop.last} “{$year.year}” {else} “{$year.year}”, {/if} {/foreach} {literal}], 数据集:[{ 标签:“平均冰川质量水平”, 数据:[{/literal} {foreach from=$glaciermass item=年份名称=glaciermassloop} {if$smarty.foreach.glaciermassloop.last} “{$year.平均累积质量平衡}” {else} “{$year.平均累积质量平衡}”, {/if} {/foreach} {literal}], 背景颜色:[ "rgba(255,99,132,0.2)",, “rgba(54162235,0.2)”, "rgba(255,206,86,0.2)",, “rgba(751921920.2)”, “rgba(153102255,0.2)”, ‘rgba(255、159、64、0.2)’ ], 边框颜色:[ "rgba(255,99,132,1)",, “rgba(54162235,1)”, "rgba(255,206,86,1)",, "rgba(751921921)",, "rgba(153102255,1)",, ‘rgba(255、159、64、1)’ ], 边框宽度:1 }] }, 选项:{ 比例:{ 雅克斯:[{ 滴答声:{ 建议最大值:0, 建议在:-30, 贝吉纳泽罗:是的 } }] } } }); {/literal}

Javascript 在smarty chartjs中显示json格式的数据 {literal} var ctx=document.getElementById('MyGlacierMarsChart').getContext('2d'); var图表=新图表(ctx{ //我们要创建的图表类型 键入:“行”, //我们的数据集的数据 数据:{ 标签:[{/literal} {foreach from=$glaciermass item=年份名称=glaciermassloop} {if$smarty.foreach.glaciermassloop.last} “{$year.year}” {else} “{$year.year}”, {/if} {/foreach} {literal}], 数据集:[{ 标签:“平均冰川质量水平”, 数据:[{/literal} {foreach from=$glaciermass item=年份名称=glaciermassloop} {if$smarty.foreach.glaciermassloop.last} “{$year.平均累积质量平衡}” {else} “{$year.平均累积质量平衡}”, {/if} {/foreach} {literal}], 背景颜色:[ "rgba(255,99,132,0.2)",, “rgba(54162235,0.2)”, "rgba(255,206,86,0.2)",, “rgba(751921920.2)”, “rgba(153102255,0.2)”, ‘rgba(255、159、64、0.2)’ ], 边框颜色:[ "rgba(255,99,132,1)",, “rgba(54162235,1)”, "rgba(255,206,86,1)",, "rgba(751921921)",, "rgba(153102255,1)",, ‘rgba(255、159、64、1)’ ], 边框宽度:1 }] }, 选项:{ 比例:{ 雅克斯:[{ 滴答声:{ 建议最大值:0, 建议在:-30, 贝吉纳泽罗:是的 } }] } } }); {/literal},javascript,php,json,smarty,Javascript,Php,Json,Smarty,我使用的是Chart.js,来自API端点的数据没有在屏幕上显示正确的平均值。我尝试了许多不同的方法,甚至尝试了选择索引,但都不起作用。目前,图表上多年来的平均值仅显示0,而不是json中的实际值-这是json本身 您尝试过按编号访问每个索引吗?您尝试过按编号访问每个索引吗 <script> {literal} var ctx = document.getElementById('myGlaciermassChart').getContext('2d'); var chart = n

我使用的是Chart.js,来自API端点的数据没有在屏幕上显示正确的平均值。我尝试了许多不同的方法,甚至尝试了选择索引,但都不起作用。目前,图表上多年来的平均值仅显示0,而不是json中的实际值-这是json本身


您尝试过按编号访问每个索引吗?

您尝试过按编号访问每个索引吗

<script>
{literal}
var ctx = document.getElementById('myGlaciermassChart').getContext('2d');
var chart = new Chart(ctx, {
    // The type of chart we want to create
    type: 'line',

    // The data for our dataset
    data: {
        labels: [{/literal}

            {foreach from=$glaciermass item=year name=glaciermassloop}
                {if $smarty.foreach.glaciermassloop.last}
                    "{$year.Year}"
                {else}
                    "{$year.Year}",
                {/if}

            {/foreach}

            {literal}],

            datasets: [{
                   label: 'Mean Glacier mass Level',
                   data: [{/literal}

                       {foreach from=$glaciermass item=year name=glaciermassloop}
                           {if $smarty.foreach.glaciermassloop.last}
                               "{$year.Mean-cumulative-mass-balance}"
                           {else}
                               "{$year.Mean-cumulative-mass-balance}",
                           {/if}
                       {/foreach}

                       {literal}],
                   backgroundColor: [
                       'rgba(255, 99, 132, 0.2)',
                       'rgba(54, 162, 235, 0.2)',
                       'rgba(255, 206, 86, 0.2)',
                       'rgba(75, 192, 192, 0.2)',
                       'rgba(153, 102, 255, 0.2)',
                       'rgba(255, 159, 64, 0.2)'
                   ],
                   borderColor: [
                       'rgba(255, 99, 132, 1)',
                       'rgba(54, 162, 235, 1)',
                       'rgba(255, 206, 86, 1)',
                       'rgba(75, 192, 192, 1)',
                       'rgba(153, 102, 255, 1)',
                       'rgba(255, 159, 64, 1)'
                   ],
                   borderWidth: 1
               }]
           },
           options: {
               scales: {
                   yAxes: [{
                       ticks: {
                           suggestedMax: 0,
                           suggestedMin:-30,
                           beginAtZero: true
                       }
                   }]
               }
           }
       });

{/literal}
</script>

<?php

$url ='https://pkgstore.datahub.io/core/glacier-mass-balance/glaciers_json/data/6270342ca6134dadf8f94221be683bc6/glaciers_json.json';

$response = file_get_contents($url);
$GlaciermassData= json_decode($response, true);

$smarty->assign('glaciermass', $GlaciermassData);
?>