生成直方图,3列为1列

时间:2014-03-24 12:21:42

标签: python django-templates google-visualization

我正在创建柱形图,但现在我想以这种方式生成该数据的直方图

['name',10,7,3]

现在我遇到了生成直方图的问题,我希望我的图表只有1列,显示pass(7)和fail(3),总共有不同的颜色(10)。

我在django模板中这样做。代码是

 google.load('visualization', '1', {packages: ['corechart','table']});
  function drawVisualization() {
    // Some raw data (not necessarily accurate)
    var data = google.visualization.arrayToDataTable([
         ['Job-Names', 'Total', 'Pass', 'Fail'],
             {{data.0|safe}}

]);

    var options = {
      title : 'Jenkins Job Details for project {{head_title}}',
      vAxis: {title: "Number of BULDS" ,ticks : [2,4,6,8,10] },
      hAxis: {title: "Job-Names" ,  slantedText:true, slantedTextAngle:30  , textStyle : {fontSize : 9}},
      is3D: true,
      height: 550,
      width: 600,
      colors : ["#194D86","#33FF66", "#FF3333"],
      pointSize: 4

    };

    var chart = new google.visualization.Histogram(document.getElementById('chart_div'));
    chart.draw(data, options);

    var table = new google.visualization.Table(document.getElementById('table_div'));
    table.draw(data, {showRowNumber: false});
  }

     google.setOnLoadCallback(drawVisualization);

数据我通过以下格式传递 [ '名称',总,通过,失败]

1 个答案:

答案 0 :(得分:0)

如果我理解你的需求,我认为你想要做的是为HistogramChart创建一个只显示name,pass和fail列的DataView:

var view = new google.visualization.DataView(data);
view.setColumns([0, 2, 3]);

var chart = new google.visualization.Histogram(document.getElementById('chart_div'));
chart.draw(view, options);