简体   繁体   English

Chart.js标题未显示

[英]Chart.js title is not showing

I am trying to load graphs based on XML data. 我正在尝试基于XML数据加载图形。 my script and everything works fine. 我的脚本,一切正常。 Just, the problem is for each of the graph , there should be a title. 只是,问题在于每个图形都应该有一个标题。 and title is not showing up at all. 标题根本不显示。 within the for loop it create the convas dynamically, and then Labels and Values are initiating when the HTML page is called. 在for循环中,它会动态创建convas,然后在调用HTML页面时启动Labels和Values。 just the missing part is the TITLE of each graph. 只是缺少的部分是每个图的标题。 any body has any idea? 任何人有什么主意吗?

var command = xmlDoc.getElementsByTagName("COMMAND");

for (var commandIndex = 0; commandIndex  < command.length; commandIndex++) {
var canvas = document.createElement('canvas');
canvas.id = "Convas"+commandIndex;
canvas.width = 800;
canvas.style.zIndex = 8;
canvas.style.position = "inherit";
document.getElementById("chartdiv").insertBefore(canvas,document.getElementById
    ("Convas"+commandIndex));
  var barData = {
 labels : [{% for item in labels %}
               "{{item}}",
          {% endfor %}],
datasets : [
   {
        fillColor: "rgba(151,187,205,0.2)",
         strokeColor: "rgba(151,187,205,1)",
        pointColor: "rgba(151,187,205,1)",
        pointStrokeColor: "#fff",
        pointHighlightFill: "#fff",
        pointHighlightStroke: "rgba(151,187,205,1)",
        bezierCurve : false,
        data : [{% for item in values %}
                  {{item}},
                {% endfor %}]
  }]
}

Chart.defaults.global.animationSteps = 50;
Chart.defaults.global.tooltipYPadding = 16;
Chart.defaults.global.tooltipCornerRadius = 0;
Chart.defaults.global.tooltipTitleFontStyle = "normal";
Chart.defaults.global.tooltipFillColor = "rgba(0,0,0,0.8)";
Chart.defaults.global.animationEasing = "easeOutBounce";
Chart.defaults.global.responsive = false;
Chart.defaults.global.scaleLineColor = "black";
Chart.defaults.global.scaleFontSize = 16;

 // get bar chart canvas

 var mychart = 
 document.getElementById("Convas"+commandIndex).getContext("2d");
 steps = 100
 max = 100
 // draw bar chart
  var LineChartDemo = new Chart(mychart).Line(barData, {
      scaleOverride: false,
      scaleSteps: steps,
      scaleStepWidth: Math.ceil(max / steps),
      scaleStartValue: 0,
      scaleShowVerticalLines: false,
      scaleShowGridLines : false,
      barShowStroke : true,
      scaleShowLabels: false,
      bezierCurve: true,
      options: { title: {display: true,text: 'FARShAD'}},
 });
}})

Well, I could not find my problem with my code. 好吧,我找不到自己的代码问题。 however, i re wrote it in another way. 但是,我用另一种方式重写了它。

var canvas = document.createElement('canvas');
canvas.id = "Convas"+commandIndex;
canvas.width = 800;
canvas.style.zIndex = 8;
canvas.style.position = "inherit";
  document.getElementById("chartdiv").insertBefore(canvas,document.getElementById("Convas"+commandIndex));

var barData = {
labels : [{% for item in labels %}
              "{{item}}",
          {% endfor %}],
datasets : [
   {
        fillColor: "rgba(151,187,205,0.2)",
        strokeColor: "rgba(151,187,205,1)",
        pointColor: "rgba(241, 14, 75, 1)",
        pointStrokeColor: "#fff",
        pointHighlightFill: "#fff",
        pointHighlightStroke: "rgba(241, 14, 75, 1)",
        backgroundColor: "rgba(241, 14, 75, 1)",
        borderColor: "rgba(241, 14, 75, 1)",
        bezierCurve : false,
        fill: false,
        label: "My First dataset",
        data : [{% for item in values %}
                  {{item}},
                {% endfor %}]
  }]
 }
   var config = {
   type: 'line',
   data: barData,
   options: {
       responsive: true,
       title:{
           display:true,
           text:'Chart.js Line Chart'
       },
       tooltips: {
           mode: 'index',
           intersect: false,
       },
       hover: {
           mode: 'nearest',
           intersect: true
       },
       scales: {
           xAxes: [{
               display: true,
               scaleLabel: {
                   display: true,
                   labelString: 'Month'
               }
           }],
           yAxes: [{
               display: true,
               scaleLabel: {
                   display: true,
                   labelString: 'Value'
               },
               ticks: {
                   min: 0,
                   max: 100,

                   // forces step size to be 5 units
                   stepSize: 5
               }
           }]
       }
   }
 };
  var mychart = 
  document.getElementById("Convas"+commandIndex).getContext("2d");

steps = 100
max = 100
// draw bar cha
  var LineChartDemo = new Chart(mychart, config);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM