简体   繁体   English

如何在谷歌图表中删除工具提示

[英]How to remove tool-tip in google chart

I am working on Google-charts, in which i am facing some issues 我正在研究Google图表,但遇到了一些问题

I am rendering a donut chart which has more then 10 data so what is happening when the width of data displaying exceeds it shows up in tool-tip like 我正在绘制一个多于10个数据的甜甜圈图,所以当数据显示的宽度超过它时,会在工具提示中显示该情况,例如

这个

which i don't want 我不要

What i am trying to do like how many headers are there let it be there not to push it into tool-tip 我正在尝试做的事情就像有多少标头一样,让它不要将其推入工具提示中

 google.charts.load('current', { 'packages': ['corechart'], 'language': 'hi_IN' }); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ["Outlet", "Amount"], ["S0001", 7153214], ["S0002", 1319026], ["S0003", 1497004], ["S0004", 1597004], ["S0005", 1697004], ["S0006", 1797004], ["S0007", 1897004], ["S0008", 13897004], ["S0009", 2097004], ["S0010", 1597004], ["S00011", 1698604] ]); var options = { pieHole: 0.6, legend: { position: 'right', }, width: 'auto', height: 'auto' }; var chart = new google.visualization.PieChart(document.getElementById('donutchart')); chart.draw(data, options); } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <div id="donutchart" style="width: 100%; height: 550px;"></div> 

I don't want to remove the legends i just want to show them in one go rather then to showing up in tool-tip where user have to click to see other legends 我不想删除这些图例,我只想一次显示它们,而是显示在工具提示中,用户必须单击以查看其他图例

Data to check 检查数据

[["Outlet","Amount"],["CHEF BAKERS BROOKFIELD",738999],["CHEF BAKERS ARAKERE",106050],["CHEF BAKERS AMEENPUR",89358],["CHEF BAKERS AYYAPPA NGR",80088],["Chef Bakers Bellandur",321705],["CHEF BAKERS BRIGADE METROPOLIS",65088],["CHEF BAKERS BAGMANE CBP",145432],["CHEF BAKERS CHANDAPURA",92830],["DIVYA SREE TECHNO PARK",82946],["Chef Bakers Doddanekkundi",92590],["CHEF BAKERS SIDDAPURA",115142],["CHEF BAKERS ECITY",163745],["CHEF BAKERS VYDEHI",84367],["CHEF BAKERS HARLUR ROAD",101337],["Chef Bakers Hennur Main Road",18045],["CHEF BAKERS HSR LAYOUT",358232],["CHEF BAKERS BOTANICAL GARDEN",22256],["CHEF BAKERS KADUBEESANAHALLI",277964],["CHEF BAKERS COFFEE BOARD",164906],["Chef Bakers Kaggadasapura",73045],["Chef Bakers Koramangala",79381],["CHEF BAKERS KASAVANAHALLI",424056],["Chef Bakers Marathahalli 1",115410],["Chef bakers Marathahalli 2",105703],["Chef Bakers Mahadevapura",209014],["CHEF BAKERS BEL LAYOUT",58661],["CHEF BAKERS MG ROAD",70005],["CHEF BAKERS MANYATA TECH PARK",105590],["CHEF BAKERS NAGAWARA",47832],["CHEF BAKERS PRESTIGE SHANTHINIKETAN",135772],["CHEF BAKERS PRITECH",301201],["RGA TECH PARK",64525],["CHEF BAKERS RAMANTHAPUR",62752],["CHEF BAKERS RR NAGAR",94200],["Chef Bakers Kadugodi",353045],["CHEF BAKERS SARJAPURA ROAD",84425],["CHEF BAKERS SINGASANDRA",60735],["CHEF BAKERS SPICE GARDEN",135243],["Chef Bakers Whitefield",427212],["CHEF BAKERS YELAHANKA",293061]]

you can use option --> legend.maxLines 您可以使用选项-> legend.maxLines
to add more lines to the legend. 为图例添加更多行。

note: this option only works with --> legend.position = top 注意:此选项仅适用于-> legend.position = top

see following working snippet... 请参阅以下工作片段...

 google.charts.load('current', { 'packages': ['corechart'], 'language': 'hi_IN' }).then(function () { var data = google.visualization.arrayToDataTable([ ["Outlet", "Amount"], ["S0001", 7153214], ["S0002", 1319026], ["S0003", 1497004], ["S0004", 1597004], ["S0005", 1697004], ["S0006", 1797004], ["S0007", 1897004], ["S0008", 13897004], ["S0009", 2097004], ["S0010", 1597004], ["S00011", 1698604] ]); var options = { pieHole: 0.6, legend: { position: 'top', maxLines: 5 }, width: 'auto', height: 'auto' }; var chart = new google.visualization.PieChart(document.getElementById('donutchart')); chart.draw(data, options); }); 
 <script src="https://www.gstatic.com/charts/loader.js"></script> <div id="donutchart" style="width: 100%; height: 550px;"></div> 

You might want to try this, 您可能想尝试一下,

legend: {
  position: 'top',
  maxLines: data.getNumberOfRows()
}

or 要么

legend: {
  position: 'top',
  maxLines: data.getNumberOfRows()/4
}

doing this it will always give you sufficient number of rows so that you can have all your legends on one page and don't have to have scroll 这样做将始终为您提供足够的行数,以便您可以将所有图例放在一页上,而不必滚动

 google.charts.load('current', { 'packages': ['corechart'], 'language': 'hi_IN' }); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ["Outlet", "Amount"], ["S0001", 7153214], ["S0002", 1319026], ["S0003", 1497004], ["S0004", 1597004], ["S0005", 1697004], ["S0006", 1797004], ["S0007", 1897004], ["S0008", 13897004], ["S0009", 2097004], ["S0010", 1597004], ["S00011", 1698604], ["S00012", 1698604], ["S00013", 1698604], ["S00014", 1698604], ["S00015", 1698604], ["S00016", 1698604], ["S00017", 1698604], ["S00018", 1698604], ["S00019", 1698604] ]); var options = { pieHole: 0.3, legend: { position: 'top', maxLines: data.getNumberOfRows() }, width: 'auto', height: 'auto' }; var chart = new google.visualization.PieChart(document.getElementById('donutchart')); chart.draw(data, options); } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <div id="donutchart" style="width: 100%; height: 550px;"></div> 

The problem is caused by the legend in the chart taking up more space than is available in the containing element. 该问题是由于图表中的图例占用的空间大于包含元素中可用的空间所致。

If you want to remove the legend, which I don't recommend as the chart becomes very unclear without it, you can set position: 'none' in the settings. 如果要删除图例,我不建议您删除图例,因为没有它,图表将变得非常不清楚,您可以在设置中设置position: 'none'

var options = {
  pieHole: 0.6,
  legend: {
    position: 'none',
  },
  width: 'auto',
  height: 'auto'
};

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

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