简体   繁体   English

Google 图表 - 标签未显示

[英]Google charts - Labels are not showing

I was trying to create 3 charts using google charts in a single line.but it not showing the labels for the values and we can see there is lot of space was vacant in between the charts.is there any way to remove that space and show the labels properly in the graph?我试图在一行中使用谷歌图表创建 3 个图表。但它没有显示值的标签,我们可以看到图表之间有很多空间。有没有办法删除那个空间并显示图中的标签是否正确?

 google.charts.load('current', { 'packages': ['corechart'] }); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ['Task', 'Hours per Day'], ['Work', 5], ['Eat', 2], ['Commute', 2], ['Watch TV', 2], ['Sleep', 7] ]); var options = { pieSliceText: 'value', pieHole: '0.5', legend: { position: 'labeled', labeledValueText: 'both', textStyle: { color: 'blue', fontSize: 14 } }, }; var chart1 = new google.visualization.PieChart(document.getElementById('chart1')); var chart2 = new google.visualization.PieChart(document.getElementById('chart2')); var chart3 = new google.visualization.PieChart(document.getElementById('chart3')); options.title = 'industries For USA'; chart1.draw(data, options); options.title = 'Categories For USA'; chart2.draw(data, options); options.title = 'Categories For Construction'; chart3.draw(data, options); }
 .chart-wrapper { float: left; width: 33%; } .top-five-charts { width: 100%; display: block; }
 <script src="https://www.gstatic.com/charts/loader.js"></script> <div class="top-five-charts"> <div class="chart-wrapper"> <div id="chart1" class="insight-pie"></div> </div> <div class="chart-wrapper"> <div id="chart2" class="insight-pie"></div> </div> <div class="chart-wrapper"> <div id="chart3" class="insight-pie"></div> </div> </div>

Here is the output in normal screen这是正常屏幕中的输出

在此处输入图片说明

Just add this line on your JavaScript code before drawing the charts:在绘制图表之前,只需在 JavaScript 代码中添加这一行:

options.chartArea = {left: '10%', width: '100%', height: '65%'};

I've also changed the legend font size to 10.我还将图例字体大小更改为 10。

It will look like this:它看起来像这样: 调整后的饼图

Here's the JSFiddle illustrating it: https://jsfiddle.net/6r3ms2tz/这是说明它的 JSFiddle: https ://jsfiddle.net/6r3ms2tz/

You should have a look responsive design principles and please check out this link: https://developers.google.com/chart/interactive/docs/basic_customizing_chart您应该看看响应式设计原则,请查看此链接: https : //developers.google.com/chart/interactive/docs/basic_customizing_chart

Simply change: 'legend':'right' according to the your choice.只需根据您的选择更改:'legend':'right'。

After several tries, below worked:经过多次尝试,以下工作:

Code:代码:

let options = {
  legend: {
    position: "labeled",
  },
  chartArea: {
    width: "100%"
  }
};

HTML for my case is below because I am using https://github.com/FERNman/angular-google-charts我的案例的 HTML 如下,因为我使用的是https://github.com/FERNman/angular-google-charts

  <google-chart
    style="width: 100%; height: 100%;"
  >
  </google-chart>

HTML for your case:您的案例的 HTML:

<div id="chart1" class="insight-pie" style="width: 100%; height: 100%;" ></div>

Hope that helps.希望有帮助。

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

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