如何在toolText中在图像上显示文本融合图表React Native

pxy2qtax  于 2023-08-07  发布在  React
关注(0)|答案(2)|浏览(169)

我正在做React本地项目,我们正在使用融合图表来显示不同的图形。但是,在这些图表,而用户点击的情节(图线)我们显示工具提示.
但是,我们必须像下面的截图显示工具提示.
注意:文本将是动态的


的数据
在工具提示属性中,我们只找到bgColor,bordercolor等,我们没有找到任何bgImage或为bg设置两个颜色。所以,我们尝试像设置图像在工具文本,但,仍然得到问题.
我们不能在图像上设置文本,它在图像的底部。

  1. {
  2. "label": "Mickey",
  3. "value": "92",
  4. "toolText": "<div class='container'><img height='50' width='50' position:relative text-align: center color: white alt='' src='http://www.pngpix.com/wp-content/uploads/2016/10/PNGPIX-COM-Mickey-Mouse-PNG-Transparent-Image-1-500x575.png'></img><div class='top-left'>Top Left</div></div>"
  5. }

字符串
输出如下。



对此有何建议?

ao218c7q

ao218c7q1#

FusionCharts工具提示不支持在工具提示中设置多个背景色。
此外,工具提示不能设置为背景图像,或者作为一种变通方法,您可以设置一个“toolText”属性。并在div中设置您的图像,如下所示:
“toolText”:“http://www.pngpix.com/wp-content/uploads/2016/10/PNGPIX-COM-Mickey-Mouse-PNG-Transparent-Image-1-500x575.png ' style=' opacity:0.5;'>
要设置文本和图像,需要使用“toolText”属性中的标签来实现:
“toolText”:“http://www.pngpix.com/wp-content/uploads/2016/10/PNGPIX-COM-Mickey-Mouse-PNG-Transparent-Image-1-500x575.png ' style=' opacity:0.5;'>居中”

ws51t4hk

ws51t4hk2#

您可以尝试这种方式,希望它能帮助您,请参考演示fiddle

  1. const dataSource = {
  2. "chart": {
  3. "caption": "Greenhouse gas emissions produced by foods ",
  4. "subCaption": "During Production",
  5. "yAxisName":"Kg Co₂E",
  6. "showValues":"0",
  7. "yAxisMaxValue":"25",
  8. "yAxisMinValue":"0",
  9. "showToolTip":"1",
  10. "theme": "fusion"
  11. },
  12. "data": [{
  13. "label": "Lamb",
  14. "value": "22"
  15. },
  16. {
  17. "label": "Beef",
  18. "value": "16"
  19. },
  20. {
  21. "label": "Farmed Salmon",
  22. "value": "4"
  23. },
  24. {
  25. "label": "White Rice",
  26. "value": "3.9"
  27. },
  28. {
  29. "label": "Brown Rice",
  30. "value": "3.54"
  31. },
  32. {
  33. "label": "Eggs",
  34. "value": "2.5"
  35. }
  36. ]
  37. };
  38. FusionCharts.ready(function() {
  39. var myChart = new FusionCharts({
  40. type: "spline",
  41. renderAt: "chart-container",
  42. width: "100%",
  43. height: "400",
  44. dataFormat: "json",
  45. dataSource
  46. }).render();
  47. function handler(eventObj, dataObj) {
  48. var id =eventObj.data.dataIndex;
  49. if(id===0)
  50. {
  51. myChart.setChartAttribute("plottooltext", "<div id='nameDiv' style='font-size: 12px; font-weight:bold; padding-bottom: 3px; text-align: center; display: inline-block;border-style: none; background-color: #ffffff;' ><img style='height:40px; width:50px;background-color: #ffffff;' src='https://2.bp.blogspot.com/-yiqNTXFRiAI/UICj02XTQ0I/AAAAAAAAAIg/xVPoKagJEm0/s1600/CABRA.jpg'</div>{br}Co<sub>2</sub>E: <b>$dataValue</b>");
  52. }
  53. else if(id===1){
  54. myChart.setChartAttribute("plottooltext", "<div id='nameDiv' style='font-size: 12px; font-weight:bold; padding-bottom: 3px; text-align: center; display: inline-block;border-style: none;background-color: #ffffff;' ><img style='height:50px; width:60px;background-color: #ffffff;' src='https://banner2.kisspng.com/20180221/vuq/kisspng-sheep-cattle-horse-livestock-farm-vector-animal-cow-5a8d75a1e781b6.1693995215192201299483.jpg'</div>{br}Co<sub>2</sub>E: <b>$dataValue</b>");
  55. }
  56. else if(id===2){
  57. myChart.setChartAttribute("plottooltext", "<div id='nameDiv' style='font-size: 12px; font-weight:bold; padding-bottom: 3px; text-align: center; display: inline-block;border-style: none;background-color: #ffffff;' ><img style='height:40px; width:50px;background-color: #ffffff;' src='https://banner2.kisspng.com/20180707/lqx/kisspng-sardine-coho-salmon-trout-atlantic-salmon-salmon-5b418018d671c4.2868322115310192888784.jpg'</div>{br}Co<sub>2</sub>E: <b>$dataValue</b>");
  58. }
  59. else if(id===3){
  60. myChart.setChartAttribute("plottooltext", "<div id='nameDiv' style='font-size: 12px; font-weight:bold; padding-bottom: 3px; text-align: center; display: inline-block;border-style: none;background-color: #ffffff;' ><img style='height:40px; width:50px;background-color: #ffffff;' src='https://cdn-a.william-reed.com/var/wrbm_gb_food_pharma/storage/images/5/1/8/1/1411815-1-eng-GB/Genetically-engineered-rice-proves-to-produce-high-yields-of-rotavirus-specific-antibody.jpg'</div>{br}Co2E: <b>$dataValue</b>");
  61. }
  62. else if(id===4){
  63. myChart.setChartAttribute("plottooltext", "<div id='nameDiv' style='font-size: 12px; font-weight:bold; padding-bottom: 3px; text-align: center; display: inline-block;border-style: none;' ><img style='height:40px; width:50px;' src='https://imageresizer.pollotropical.fuzzhq.com/resize/?source=https://koala-marketing-api-production.s3.amazonaws.com/pollo-tropical/assets/BrownRice.png&height=9999&width=600&max_quality=85'</div>{br}Co<sub>2</sub>E: <b>$dataValue</b>");
  64. }
  65. else if(id===5){
  66. myChart.setChartAttribute("plottooltext", "<div id='nameDiv' style='font-size: 12px; font-weight:bold; padding-bottom: 3px; text-align: center; display: inline-block;border-style: none;' ><img style='height:40px; width:50px;' src='https://us.123rf.com/450wm/andegro4ka/andegro4ka1504/andegro4ka150400029/39383340-stock-vector-broken-egg-shells-isolated-on-white-photo-realistic-vector-illustration.jpg?ver=6'</div>{br}Co<sub>2</sub>E: <b>$dataValue</b>");
  67. }
  68. }
  69. myChart.addEventListener("dataplotRollOver", handler);

字符串
});
参考文档-https://www.fusioncharts.com/features/tooltips

展开查看全部

相关问题