График с использованием CanvasJS пуст, когда я использую определенный формат dateTime - PullRequest
0 голосов
/ 09 ноября 2018

Я использую CanvasJS, чтобы показать график на своей странице. x содержит даты и y числа.

Я установил:

xValueType: "dateTime",
xValueFormatString: "YYYY-MM-DD HH:mm",

для форматирования моих дат, например '2018-11-08 13:11' но график пуст .. Что-то не так с dateFormat, но я не могу понять, что это ...

window.onload = function() {

  var chart = new CanvasJS.Chart("grafima1", {
    animationEnabled: true,
    title: {
      text: "title"
    },
    axisX: {
      title: "date"
    },
    axisY: {
      title: "Num",
      suffix: "",
      stripLines: [{
        value: 3,
        label: "3"
      }]
    },
    data: [{
      type: "line",
      name: "Ώρες",
      connectNullData: true,
      xValueType: "dateTime",
      xValueFormatString: "YYYY-MM-DD HH:mm",
      yValueFormatString: "#,##0.##",
      dataPoints: [{
          x: '2018-11-08 13:11',
          y: 2.0
        },
        {
          x: '2018-11-05 15:23',
          y: 5.0
        }

      ]
    }]
  });
  chart.render();


};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>

<div id="grafima1" style="height: 370px; width: 100%;"></div>

1 Ответ

0 голосов
/ 09 ноября 2018

window.onload = function () {

        var chart = new CanvasJS.Chart("grafima1", {
            animationEnabled: true,
            title: {
                text: "title"
            },
            axisX: {
                title: "date"
            },
            axisY: {
                title: "Num",
                suffix: "",
                stripLines: [{
                    value: 3,
                    label: "3"
                }]
            },
            data: [{
                type: "line",
                name: "Ώρες",
                connectNullData: true,
                xValueType: "dateTime",
                xValueFormatString: "YYYY-MM-DD HH:mm",
                yValueFormatString: "#,##0.##",
                dataPoints: [{
                    x: new Date("2018-11-08 13:11"),
                    y: 2.0
                },
                {
                    x: new Date("2018-11-05 15:23"),
                    y: 5.0
                }
                ]
            }]
        });
        chart.render();

    };
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="grafima1" style="height: 370px; width: 100%;"></div>

enter image description here

...