doukang7858 2019-08-07 09:03 采纳率: 0%
浏览 53

传说没有显示

<Div>is defined in the html code for line chart representation.The data is populated from database and the graph is plotted based on the same data but legends are not displayed.

HTML CODE

<div id="chart-container">
        <canvas id="scurve_chart"></canvas>
</div>

javascript code

The data populated from database is converted to json_encode format and saved to an array.from this array data are taken and ploted in the graph .

 $(document).ready(function () {
            show_scurve_Graph();

   });
   function show_scurve_Graph()
        {
            {
                var data = <?php echo json_encode($data_plan); ?>;

                    //console.log();
                     var labels = [];
                    var chart1 = [];
                    var chart2 = [];
                    var chart3 = [];
                    var spent = [];

                    for (var i in data) {
                        labels.push(data[i].label);
                        chart1.push(data[i].chart1);
                        chart2.push(data[i].chart2);
                        chart3.push(data[i].chart3);
                        spent.push(data[i].spent);


                        }


                    var chartdata = {
                        labels: labels,

                        datasets: [

                            {
                                label: "BASELINE1",
                                fill: false,
                                //lineTension: 0.1,
                                //backgroundColor: "rgba(255, 0, 0, 0.75)",
                                borderColor: "rgba(255, 0, 0, 1)",
                                pointHoverBackgroundColor: "rgba(255, 0, 0, 1)",
                                //pointHoverBorderColor: "rgba(255, 0, 0, 1)",
                                data: chart1
                            },
                            {
                                label: "BASELINE2",
                                fill: false,
                                //lineTension: 0.1,
                                backgroundColor: "rgba(0, 255, 0, 0.75)",
                                borderColor: "rgba(0, 255, 0, 1)",
                                pointHoverBackgroundColor: "rgba(0, 255, 0, 1)",
                                pointHoverBorderColor: "rgba(0, 255, 0, 1)",
                                data: chart2
                            },
                            {
                                label: "BASELINE3",
                                fill: false,
                                //lineTension: 0.1,
                                backgroundColor: "rgba(0, 0, 255, 0.75)",
                                borderColor: "rgba(0, 0, 255, 1)",
                                pointHoverBackgroundColor: "rgba(0, 0, 255, 1)",
                                pointHoverBorderColor: "rgba(0, 0, 255, 1)",
                                data: chart3
                            },
                            {
                                label: "Actual Spent",
                                fill: false,
                                backgroundColor: "rgba(50, 50, 50, 0.75)",
                                borderColor: "rgba(50, 50, 50, 1)",
                                pointHoverBackgroundColor: "rgba(50, 50, 50, 1)",
                                pointHoverBorderColor: "rgba(50, 50, 50, 1)",
                                data: spent
                            }

                        ]

                    };

                    var graphTarget = $("#scurve_chart");

                  var barGraph = new Chart(graphTarget, {
                        type: 'line',
                        data: chartdata,
                        options: {
                            elements: {
                    point:{
                        radius: 0,
                    }
                },


        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero: true
                }
            }],
            xAxes: [{
            barValueSpacing: 2,
            barPercentage: 0.2
        }]
        }
    }
                    });

            }}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算
    • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
    • ¥20 有人知道这种图怎么画吗?
    • ¥15 pyqt6如何引用qrc文件加载里面的的资源
    • ¥15 安卓JNI项目使用lua上的问题
    • ¥20 RL+GNN解决人员排班问题时梯度消失
    • ¥60 要数控稳压电源测试数据
    • ¥15 能帮我写下这个编程吗
    • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路