【问题标题】:Highchart Pie Chart shows "slice 0.0%" when loading data from csv从 csv 加载数据时,Highchart 饼图显示“切片 0.0%”
【发布时间】:2017-07-21 09:36:08
【问题描述】:

我尝试从 CSV 数据加载数据以创建饼图。 总是有切片显示“切片:0.0%”。但是,在我的 CSV 数据中,没有所谓的切片数据。我想知道这是因为 highchart 的默认设置还是因为我使用错误的方式读取 CSV 数据文件。

Jsfiddle_code

下面是图表的照片。

var pie_bl = Papa.parse(document.getElementById('pie_bl').innerHTML);
Highcharts.chart('container', {
  chart: {
    plotBackgroundColor: null,
    plotBorderWidth: null,
    plotShadow: false,
    type: 'pie'
  },
  data: {
    rows: pie_bl.data
  },
  title: {
    text: 'Pie Chart_csv'
  },
  tooltip: {
    pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
  },
  plotOptions: {
    pie: {
      allowPointSelect: true,
      cursor: 'pointer',
      dataLabels: {
        enabled: true,
        format: '<b>{point.name}</b>: {point.percentage:.1f} %',
        style: {
          color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
        }
      }
    }
  },
});
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/data.js"></script>
<script src="https://rawgit.com/mholt/PapaParse/master/papaparse.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>

<pre id="pie_bl" style="display:none">Category,Allocation
a,0.45,
b,0.5,
c,1.25,
d,0.15, 
e,0.1,
f,0.55,
</pre>

【问题讨论】:

    标签: javascript csv highcharts


    【解决方案1】:

    &lt;pre&gt; 标记中的 CSV 数据以 和 new-line 结尾。在 CSV 中,这将被视为另一个条目。这就是它显示 Slice: 0.0 的原因。

    默认情况下,Highcharts 将标签分配为 Slice,如果未提及,则将值分配为 0。所以你的&lt;pre&gt; 标签应该是这样的

    <pre id="pie_bl" style="display:none">
        Category,Allocation
        a,0.45
        a,0.45,
        b,0.5,
        c,1.25,
        d,0.15, 
        e,0.1,
        f,0.55</pre>
    

    更新你的小提琴here

    【讨论】:

      【解决方案2】:

      您的值将使用正确的逗号

      <pre id="pie_bl" style="display:none">Category,Allocation,
      a,0.45,
      b,0.5,
      c,1.25,
      d,0.15, 
      e,0.1,
      f,0.55,</pre>
      

      Fiddle

      【讨论】:

        猜你喜欢
        • 2017-10-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-09
        • 2013-10-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多