Y轴中的值不在morris javascript中传递

时间:2017-07-27 08:53:45

标签: php html mysql morris.js

我试图通过使用morris javascript从mysql传递值来显示动态条形图。但是只传递x轴的值。因此该图是空白的。我做了所有的研究,我找不到它。我需要你的帮助。我是编程新手。

Morris.Bar({
 element : 'chart',
 data:[<?php echo $chart_data; ?>],
 xkey:'gp_submit',
 ykeys:['cnt'],
 labels:['Submitted','cnt'],
 hideHover:'auto',
 stacked:true
});
<?php $connect = mysqli_connect("localhost", "root", "", "hr");
$query = "SELECT gp_submit AS dt, name AS cnt FROM `emp_det` where gp_submit>=DATE_SUB(NOW(), INTERVAL 1 WEEK) GROUP BY gp_submit";
$result = mysqli_query($connect, $query);
$chart_data = '';
while($row = mysqli_fetch_array($result))
{
 $chart_data .= "{ gp_submit:'".$row["dt"]."', cnt:'".$row["cnt"]."'}, ";
}
$chart_data = substr($chart_data, 0, -2);
?>
<div id="chart" style="width:100%; height:280px;"></div>

2 个答案:

答案 0 :(得分:0)

因为你没有在那里传递正确的Morris.Bar({ element : 'chart', data:<?php echo json_encode($chart_data, JSON_NUMERIC_CHECK); ?>, xkey:'gp_submit', ykeys:['cnt'], labels:['Submitted','cnt'], hideHover:'auto', stacked:true });

尝试这样

ChartObject

在JS中:

Option Explicit

Sub chartstatus()

Dim Rng As Range
Dim ChtObj As ChartObject

Set rng = ActiveSheet.Range("A2:E53")

' use ChartObject instead of shape
Set ChtObj = ActiveSheet.ChartObjects.Add(100, 100, 500, 500) '<-- default dimension and location >> can modify later
With ChtObj
    .Chart.ChartType = xlColumnClustered
    .Chart.SetSourceData Rng

    With .Chart
        .Axes(xlSecondary).TickLabels.NumberFormat = "0.0%"

        .SeriesCollection(1).Format.Fill.ForeColor.RGB = RGB(255, 255, 255) '<~~ Red
        .SeriesCollection(2).Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
        .SeriesCollection(3).Format.Fill.ForeColor.RGB = RGB(0, 255, 0)
        .HasTitle = True
        .ChartTitle.Text = "Result 2017"
    End With

    ' set position of the chart to Cell G7
    .Top = Range("G7").Top
    .Left = Range("G7").Left

    ' change the dimensions of the chart
    With .Chart.ChartArea
        .Width = 1060
        .Height = 420
    End With
End With

End Sub

它应该有用;

答案 1 :(得分:0)

new Morris.Bar({
     element: "bargraph",
     data: d_data,//getBarData(data,periodvalue,year),//data,
     xkey: "day",
     ykeys: ["total","confirm"],
     xLabels:'day Month',
     labels: [total,confirm],
     barColors: ['#0b62a4','#7BB661']
});

Morris.Bar({
    element : 'chart',
    data:[<?php echo $chart_data; ?>],
    xkey:'gp_submit',
    ykeys:['here you haveto put value','cnt'],
    labels:['Submitted','cnt'],
    hideHover:'auto',
    stacked:true
});