2015-12-15 36 views
3

请告诉我们如何制作水平图例。如何制作图例水平

而且这里的结果:

enter image description here

但我想这一点: enter image description here

我有以下代码:

<script type="text/javascript"> 
 

 
     //$(function() { 
 
     function getJson() { 
 
      var result = []; 
 
      $.ajax({ 
 
       url: "WebService1.asmx/GetJson3", 
 
       success: function (data) { 
 
        $.each(data, function (key, value) { 
 
         item = { 
 
          "company": value.BusinessUnitName, 
 
          "revenue": value.QTY_Case, 
 
          "expenses": value.QTY_Case_Target, 
 
          "cos": value.QTY_Case_LY 
 
         } 
 
         result.push(item); 
 
        }); 
 
       }, 
 
       async: false, 
 
      }); 
 

 
      $("#columnChart").igDataChart({ 
 
       width: "280px", 
 
       height: "200px", 
 
       dataSource: result, 
 
       legend: { 
 
        element: "columnLegend" 
 
       }, 
 

 
       title: "title", 
 
       subtitle: "subtitle", 
 

 
       axes: [{ 
 
        name: "xAxis", 
 
        type: "categoryX", 
 
        //label: "company", 
 
        labelTopMargin: 5, 
 
        gap: 0.4, 
 
        overlap: 0.0, 
 
    
 
       }, { 
 
        name: "yAxis", 
 
        type: "numericY", 
 
        maximumValue: 250000, 
 
        interval: 50, 
 
        minimumValue: 0, 
 
        formatLabel: function (val) { 
 
         var bVal = (val/10000), 
 
         rounded = Math.round(bVal * 100)/100; 
 
         return rounded + "M"; 
 
        } 
 
       }], 
 
       series: [{ 
 
        name: "series1", 
 
        title: "revenue", 
 
        type: "column", 
 
        isTransitionInEnabled: true, 
 
        xAxis: "xAxis", 
 
        yAxis: "yAxis", 
 
        valueMemberPath: "revenue" 
 
       }, { 
 
        name: "series2", 
 
        title: "expenses", 
 
        type: "column", 
 
        isTransitionInEnabled: true, 
 
        xAxis: "xAxis", 
 
        yAxis: "yAxis", 
 
        valueMemberPath: "expenses" 
 
       }, { 
 
        name: "series3", 
 
        title: "cos", 
 
        type: "column", 
 
        isTransitionInEnabled: true, 
 
        xAxis: "xAxis", 
 
        yAxis: "yAxis", 
 
        valueMemberPath: "cos" 
 
       }, 
 
       ] 
 
      }); 
 

 
     } 
 
     $(function() { 
 
      getJson(); 
 
     }); 
 

 
    </script>

我希望能有所指导。 谢谢, 最好的方面

+0

我不知道HTML输出是什么样子,但你也许能的三个要素(收入,支出,COS)设置为每个有'display'在CSS'直列block'的。因为你在这里有CSS标签。 – Sam

+1

https://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=igDataChart+horizo​​ntal+legend第一个结果是有人问同一个问题,他们得到了答案 –

+0

感谢山姆和安德鲁骨头 这是非常好的意见。我只是添加了一些代码,因为他们引导你。这是成功。 最好的方面 – hibino

回答

0

这个问题在Andrew Bone提供的链接中回答。我将在这里发布答案,以便它可见。

使属于图例的表格行显示为inline-block

#columnLegend tr { 
    display: inline-block; 
} 

另一个建议,我已经根据您提供的是不使$.ajax调用同步的代码。只需在成功回调中初始化igDataChart即可。

$.ajax({ 
    url: "WebService1.asmx/GetJson3", 
    success: function (data) { 
     $.each(data, function (key, value) { 
      item = { 
       "company": value.BusinessUnitName, 
       "revenue": value.QTY_Case, 
       "expenses": value.QTY_Case_Target, 
       "cos": value.QTY_Case_LY 
      } 
      result.push(item); 
      initChart(); 
     }); 
    } 
}); 
+0

你好康斯坦丁Dinev, \t 感谢您的意见。 我添加了代码: #columnLegend tr {display:inline-block;}。其中