Jquery Canvas JS 图表错误 - 当在数据点上传递变量时,它会在放置静态值时给出错误

问题描述 投票:0回答:0

Jquery Canvas JS 图表错误 - 当在数据点上传递变量时,它会在放置静态值时给出错误

` var chart = new CanvasJS.Chart(DisplayDiv, {

            animationEnabled: true,
            title: {
                text: "Design"
            },
            axisX: {
                interval: 1,
                intervalType: "month",
                valueFormatString: "MMM"
            },
            axisY: {
                suffix: "%"
            },
            toolTip: {
                shared: true
            },
            legend: {
                reversed: true,
                verticalAlign: "bottom",
                horizontalAlign: "bottom"
            },
            data: [
                {
                    type: "stackedColumn100",
                    name: "01-9",
                    showInLegend: true,
                    xValueFormatString: "MMM",
                    yValueFormatString: "#,##00.00\"\"",
                    dataPoints: [{x: new Date(2023,1,15), y:3.70},{x: new Date(2023,2,15), y:33.94},{x: new Date(2023,3,15), y:19.51}]
                },
                {
                    type: "stackedColumn100",
                    name: "10-12",
                    showInLegend: true,
                    xValueFormatString: "MMM",
                    yValueFormatString: "#,##00.00\"\"",
                    dataPoints: [{x: new Date(2023,1,15), y:0.00},{x: new Date(2023,2,15), y:21.21},{x: new Date(2023,3,15), y:75.61}]
                },
                {
                    type: "stackedColumn100",
                    name: "13-18",
                    showInLegend: true,
                    xValueFormatString: "MMM",
                    yValueFormatString: "#,##00.00\"\"",
                    dataPoints: [{x: new Date(2023,1,15), y:6.17},{x: new Date(2023,2,15), y:24.24},{x: new Date(2023,3,15), y:4.88}]
                },
                {
                    type: "stackedColumn100",
                    name: ">24",
                    showInLegend: true,
                    xValueFormatString: "MMM",
                    yValueFormatString: "#,##00.00\"\"",
                    dataPoints: [{x: new Date(2023,1,15), y:90.12},{x: new Date(2023,2,15), y:13.33},{x: new Date(2023,3,15), y:0.00}]
                },
                
            ]
        });
        chart.render();
    }`

此代码有效,如果我从 Varial 传递然后给出错误,我尝试以下

var One = '{x: new Date(2023,1,15), y:3.70},{x: new Date(2023,2,15), y:33.94},{x: new Date(2023,3,15), y:19.51}';
                 {
                    type: "stackedColumn100",
                    name: ">24",
                    showInLegend: true,
                    xValueFormatString: "MMM",
                    yValueFormatString: "#,##00.00\"\"",
                    dataPoints: [One]
                },

案例二

{
                    type: "stackedColumn100",
                    name: ">24",
                    showInLegend: true,
                    xValueFormatString: "MMM",
                    yValueFormatString: "#,##00.00\"\"",
                    dataPoints: [eval(One)]
                }, 

不工作评估和变量不工作我尝试这样做可能吗?`

jquery canvasjs
© www.soinside.com 2019 - 2024. All rights reserved.