Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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
在wordpress页面中使用javascript_Javascript_Wordpress - Fatal编程技术网

在wordpress页面中使用javascript

在wordpress页面中使用javascript,javascript,wordpress,Javascript,Wordpress,我有一个脚本,用户可以输入1到10之间的值,然后将结果显示在雷达图上 一些JS: var radarChartData = { labels: ["OPTION - 1", "OPTION - 2", "OPTION - 3", "OPTION - 4", "OPTION - 5", "OPTION - 6", "OPTION - 7", "OPTION - 8", "OPTION - 9", "OPTION - 10", "OPTION - 11", "OPTION - 12"],

我有一个脚本,用户可以输入1到10之间的值,然后将结果显示在雷达图上

一些JS:

var radarChartData = {
    labels: ["OPTION - 1", "OPTION - 2", "OPTION - 3", "OPTION - 4", "OPTION - 5", "OPTION - 6", "OPTION - 7", "OPTION - 8", "OPTION - 9", "OPTION - 10", "OPTION - 11", "OPTION - 12"],
    datasets: [
        {
            label: "Wheel Of Life",
            fillColor: "rgba(220,220,220,0.2)",
            strokeColor: "rgba(255,153,0,1)",
            pointColor: "rgba(220,220,220,1)",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "rgba(255,153,0,1)",
            data: [10,10,10,10,10,10,10, 10, 10, 10,10, 10]
        }

    ]
};

//This is the function that renders the chart for the first time
    window.onload = function(){
    window.myRadarChart = new Chart(document.getElementById("canvas").getContext("2d")).Radar(radarChartData, {
        responsive: true
    });


}

 //For Every Change of value this is the function that renders the chart. All the actions have to be attached to this function. That should be pretty much it. 
    function runSubmitFunction() {
    //myRadarChart.datasets[0].points[0].value = 
    var datalist = document.getElementById ("browsers");
myRadarChart.datasets[0].points[0].value = document.getElementById ("data1").value;
    myRadarChart.datasets[0].points[1].value = document.getElementById ("data2").value;
    myRadarChart.datasets[0].points[2].value = document.getElementById ("data3").value;
myRadarChart.datasets[0].points[3].value = document.getElementById ("data4").value;
  myRadarChart.datasets[0].points[4].value = document.getElementById ("data5").value;
    myRadarChart.datasets[0].points[5].value = document.getElementById ("data6").value;
    myRadarChart.datasets[0].points[6].value = document.getElementById ("data7").value;
    myRadarChart.datasets[0].points[7].value = document.getElementById ("data8").value;
    myRadarChart.datasets[0].points[8].value = document.getElementById ("data9").value;
    myRadarChart.datasets[0].points[9].value = document.getElementById ("data10").value;
    myRadarChart.datasets[0].points[10].value = document.getElementById ("data11").value;
    myRadarChart.datasets[0].points[11].value = document.getElementById ("data12").value;
    myRadarChart.update();
     }

我在wordpress中尝试了很多东西,但都无法在header.php中引用chart.js,多种多样的将demo.html中的代码发布到wordpress页面等。

您必须使用下面的函数将chart.js文件包含在wordpress主页的标题部分。您必须在function.php文件中编写此函数,以便在主页标题中包含此chart.js文件,以便从到处都是

function wps_poll_options_page () {

 wp_enqueue_script(
        'getChart', // name your script so that you can attach other scripts and de-register, etc.
        get_template_directory_uri() . '/js/chart.js', // this is the location of your script file
        array('jquery') // this array lists the scripts upon which your script depends
    );

谢谢你的帮助。我将您的代码放入function.php中,并将chart.js放入/js/chart.js中,然后将heml添加到wordpress页面,但它不起作用。不确定为什么不是..@user3581315请尝试查看页面源代码,以便了解是否包含js文件。