日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
前端開發(fā)者常用的9個(gè)JavaScript圖表庫(kù)

當(dāng)前,數(shù)據(jù)可視化已經(jīng)成為數(shù)據(jù)科學(xué)領(lǐng)域非常重要的一部分。不同網(wǎng)絡(luò)系統(tǒng)中產(chǎn)生的數(shù)據(jù),都需要經(jīng)過(guò)適當(dāng)?shù)目梢暬幚?,以便更好的呈現(xiàn)給用戶讀取和分析。

創(chuàng)新互聯(lián)公司專注于崇仁企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,成都商城網(wǎng)站開發(fā)。崇仁網(wǎng)站建設(shè)公司,為崇仁等地區(qū)提供建站服務(wù)。全流程按需定制設(shè)計(jì),專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)

對(duì)任何一個(gè)組織來(lái)說(shuō),如果能夠充分的獲取數(shù)據(jù)、可視化數(shù)據(jù)和分析數(shù)據(jù),那么就能很大程度上幫助了解數(shù)據(jù)產(chǎn)生的深層次原因,以便據(jù)此做出正確的決定。

對(duì)于前端開發(fā)人員來(lái)說(shuō),如果能夠掌握交互式網(wǎng)頁(yè)中的數(shù)據(jù)可視化技術(shù),則是一項(xiàng)很棒的技能。當(dāng)然,通過(guò)一些 JavaScript 的圖表庫(kù)也會(huì)使前端的數(shù)據(jù)可視化變得更加容易。使用這些庫(kù),開發(fā)者可以在無(wú)需考慮不同的語(yǔ)法所帶來(lái)的編程難題的情況下,輕松實(shí)現(xiàn)將數(shù)據(jù)轉(zhuǎn)化為易于理解的圖表。

下面是挑選出的9個(gè) JavaScript 圖表庫(kù):

  • Chart.js
  • Chartist
  • FlexChart
  • Echarts
  • NVD3
  • C3.js
  • TauCharts
  • ReCharts
  • Flot

Chart.js

Chart.js 是一種簡(jiǎn)潔、用戶友好的圖表庫(kù),同時(shí)也是基于 HTML5 的 JavaScript 庫(kù),用于創(chuàng)建動(dòng)畫、交互式和可自定義的圖表和圖形。

借助 Chart.js,用戶可以輕松直觀地查看混合圖表類型。默認(rèn)情況下,也可以使用 Chart.js 創(chuàng)建響應(yīng)式網(wǎng)頁(yè)。

Chart.js 庫(kù)允許用戶快速創(chuàng)建可視化數(shù)據(jù)。Chart.js 易于設(shè)置,對(duì)初學(xué)者十分友好。使用 Chart.js 則不必考慮瀏覽器的兼容性問(wèn)題,因?yàn)?Chart.js 支持舊瀏覽器。

使用 npm 安裝 Chart.js:

  
 
 
 
  1. npm install chart.js --save 

Chart.js 繪制雷達(dá)圖的代碼示例:

  
 
 
 
  1. const options = { 
  2.  scale: { 
  3.  // Hides the scale 
  4.  } 
  5. }; 
  6. const data = { 
  7.  labels: ['Running', 'Swimming', 'Eating', 'Cycling'], 
  8.  datasets: [ 
  9.        { 
  10.  data: [-10, -5, -3, -15], 
  11.  label: "two", 
  12.  borderColor: '#ffc63b' 
  13.  }, 
  14.       { 
  15.  data: [10, 5, 3, 10], 
  16.  label: "three", 
  17.  borderColor: '#1d9a58' 
  18.  }, 
  19.  { 
  20.  data: [18, 10, 4, 2], 
  21.  label: "one", 
  22.  borderColor: '#d8463c' 
  23.  }, 
  24. const myRadarChart = new Chart(ctx, { 
  25.  data: data, 
  26.  type: 'radar', 
  27.  options: options 
  28. }); 

Chartist

Chartist 庫(kù)很適合于創(chuàng)建美觀、響應(yīng)能力強(qiáng)、閱讀友好的圖表。Chartist 使用 SVG 來(lái)呈現(xiàn)圖表。

Chartist 還提供了使用 CSS 媒體查詢和創(chuàng)意動(dòng)畫來(lái)自定義圖表的能力。用戶使用 Chartist 在圖表設(shè)計(jì)中實(shí)現(xiàn)自己的所有創(chuàng)意。

Chartist 易于配置,也易于使用 Sass 進(jìn)行定制。但是,它不支持舊瀏覽器。

使用 Chartist,可以通過(guò) CSS 的樣式來(lái)美化你的 SVG,用戶完全可以現(xiàn)實(shí)自己所想的所有圖表樣式。

使用 npm 安裝 Chartist:

  
 
 
 
  1. npm install chartist --save 

Chartist 創(chuàng)建具有自定義標(biāo)簽的餅圖的代碼示例:

  
 
 
 
  1. var data = { 
  2.  labels: ['Bananas', 'Apples', 'Grapes'], 
  3.  series: [20, 15, 40] 
  4. }; 
  5. var options = { 
  6.  labelInterpolationFnc: function(value) { 
  7.  return value[0] 
  8.  } 
  9. }; 
  10. var responsiveOptions = [ 
  11.  ['screen and (min-width: 640px)', { 
  12.  chartPadding: 30, 
  13.  labelOffset: 130, 
  14.  labelDirection: 'explode', 
  15.  labelInterpolationFnc: function(value) { 
  16.  return value; 
  17.  } 
  18.  }], 
  19.  ['screen and (min-width: 1024px)', { 
  20.  labelOffset: 80, 
  21.  chartPadding: 20 
  22.  }] 
  23. ]; 
  24. new Chartist.Pie('.ct-chart', data, options, responsiveOptions); 

FlexChart 是高性能的圖表工具。使用 FlexChart,可輕松的將表格數(shù)據(jù)可視化為業(yè)務(wù)圖表。FlexChart 不但支持常見的圖表類型,如折線圖、餅狀圖、面積圖等,還支持氣泡圖、K線圖、條形圖、漏斗圖等高級(jí)圖表類型。

FlexChart 的使用也十分簡(jiǎn)單,F(xiàn)lexChart 圖表將所有與數(shù)據(jù)有關(guān)的任務(wù)都委托給 CollectionView 類,只需操作 CollectionView 類,就能實(shí)現(xiàn)過(guò)濾、排序和分組數(shù)據(jù)等功能。

FlexChart 包含的圖表元素也比較全面,如圖表圖例、圖表標(biāo)題、圖表頁(yè)腳、數(shù)軸、圖表 series 和標(biāo)簽等,用戶也可以為圖表添加自定義的元素,如平均線和趨勢(shì)線等。

FlexChart 本質(zhì)上是一種交互式的圖表,不論是數(shù)據(jù)進(jìn)行任何的更改,都會(huì)自動(dòng)反應(yīng)在圖表上,如圖表曲線隨數(shù)據(jù)放大縮小、過(guò)濾、鉆取、動(dòng)畫等。

查看 FlexChart 的中文學(xué)習(xí)指南和旭日?qǐng)DDemo。

FlexChart 繪制柱狀圖的代碼示例:

  
 
 
 
  1. onload = function() { 
  2.  // wrap data in a CollectionView so the grid and chart  
  3.  // get notifications 
  4.  var data = new wijmo.collections.CollectionView(getData()); 
  5.  // create the chart 
  6.  var theChart = new wijmo.chart.FlexChart('#theChart', { 
  7.  itemsSource: data, 
  8.  bindingX: 'country', 
  9.  series: [ 
  10.  { binding: 'sales', name: 'Sales' }, 
  11.  { binding: 'expenses', name: 'Expenses' }, 
  12.  { binding: 'downloads', name: 'Downloads' } 
  13.  ] 
  14.  }) 
  15.  // create a grid to show the data 
  16.  var theGrid = new wijmo.grid.FlexGrid('#theGrid', { 
  17.  itemsSource: data 
  18.  }) 
  19.  // create some random data 
  20.  function getData() { 
  21.  var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','), 
  22.  data = []; 
  23.  for (var i = 0; i < countries.length; i++) { 
  24.  data.push({ 
  25.  country: countries[i], 
  26.  sales: Math.random() * 10000, 
  27.  expenses: Math.random() * 5000, 
  28.  downloads: Math.round(Math.random() * 20000), 
  29.  }); 
  30.  } 
  31.  return data; 
  32.  } 

Echarts

Echarts 是網(wǎng)頁(yè)的數(shù)據(jù)可視化方面的一個(gè)非常有用的庫(kù)。使用 Echarts,開發(fā)者可以創(chuàng)建直觀的、可自定義的交互式圖表,讓數(shù)據(jù)的展示和分析變得十分容易。

由于 Echarts 是用普通的 JavaScript 編寫的,所以 Echarts 不存在其它圖表庫(kù)存在的無(wú)法無(wú)縫遷移的問(wèn)題。

同時(shí),Echarts 也提供了很多官方文檔供用戶查看。

使用 npm 可以很容易的完成 Echarts 的安裝: 

  
 
 
 
  1. npm install echarts --save 

Echarts 繪制散點(diǎn)圖代碼示例:

  
 
 
 
  1. var dom = document.getElementById("container"); 
  2. var myChart = echarts.init(dom); 
  3. var app = {}; 
  4. option = null; 
  5. option = { 
  6.  title: { 
  7.  text: 'Large-scale scatterplot' 
  8.  }, 
  9.  tooltip : { 
  10.  trigger: 'axis', 
  11.  showDelay : 0, 
  12.  axisPointer:{ 
  13.  show: true, 
  14.  type : 'cross', 
  15.  lineStyle: { 
  16.  type : 'dashed', 
  17.  width : 1 
  18.  } 
  19.  }, 
  20.  zlevel: 1 
  21.  }, 
  22.  legend: { 
  23.  data:['sin','cos'] 
  24.  }, 
  25.  toolbox: { 
  26.  show : true, 
  27.  feature : { 
  28.  mark : {show: true}, 
  29.  dataZoom : {show: true}, 
  30.  dataView : {show: true, readOnly: false}, 
  31.  restore : {show: true}, 
  32.  saveAsImage : {show: true} 
  33.  } 
  34.  }, 
  35.  xAxis : [ 
  36.  { 
  37.  type : 'value', 
  38.  scale:true 
  39.  } 
  40.  ], 
  41.  yAxis : [ 
  42.  { 
  43.  type : 'value', 
  44.  scale:true 
  45.  } 
  46.  ], 
  47.  series : [ 
  48.  { 
  49.  name:'sin', 
  50.  type:'scatter', 
  51.  large: true, 
  52.  symbolSize: 3, 
  53.  data: (function () { 
  54.  var d = []; 
  55.  var len = 10000; 
  56.  var x = 0; 
  57.  while (len--) { 
  58.  x = (Math.random() * 10).toFixed(3) - 0; 
  59.  d.push([ 
  60.  x, 
  61.  //Math.random() * 10 
  62.  (Math.sin(x) - x * (len % 2 ? 0.1 : -0.1) * Math.random()).toFixed(3) - 0 
  63.  ]); 
  64.  } 
  65.  //console.log(d) 
  66.  return d; 
  67.  })() 
  68.  }, 
  69.  { 
  70.  name:'cos', 
  71.  type:'scatter', 
  72.  large: true, 
  73.  symbolSize: 2, 
  74.  data: (function () { 
  75.  var d = []; 
  76.  var len = 20000; 
  77.  var x = 0; 
  78.  while (len--) { 
  79.  x = (Math.random() * 10).toFixed(3) - 0; 
  80.  d.push([ 
  81.  x, 
  82.  //Math.random() * 10 
  83.  (Math.cos(x) - x * (len % 2 ? 0.1 : -0.1) * Math.random()).toFixed(3) - 0 
  84.  ]); 
  85.  } 
  86.  //console.log(d) 
  87.  return d; 
  88.  })() 
  89.  } 
  90.  ] 
  91. }; 
  92. if (option && typeof option === "object") { 
  93.  myChart.setOption(option, true); 

NVD3

NVD3 是由 Mike Bostock 撰寫的基于 D3 的 JavaScript 庫(kù)。NVD3 允許用戶在 Web 應(yīng)用程序中創(chuàng)建美觀的、可復(fù)用的圖表。

NVD3 具有很強(qiáng)大的圖表功能,能夠很方便的創(chuàng)建箱形圖、旭日形和燭臺(tái)圖等。如果用戶想在 JavaScript 圖表庫(kù)中用到大量的能力,推薦試用 NVD3。

NVD3 圖表庫(kù)的速度有時(shí)可能會(huì)成為一個(gè)問(wèn)題,與 Fastdom 安裝配合使用,速度會(huì)更快。

NVD3 繪制簡(jiǎn)單的折線圖代碼示例:

  
 
 
 
  1. /*These lines are all chart setup. Pick and choose which chart features you want to utilize. */ 
  2. nv.addGraph(function() { 
  3.  var chart = nv.models.lineChart() 
  4.  .margin({left: 100}) //Adjust chart margins to give the x-axis some breathing room. 
  5.  .useInteractiveGuideline(true) //We want nice looking tooltips and a guideline! 
  6.  .transitionDuration(350) //how fast do you want the lines to transition? 
  7.  .showLegend(true) //Show the legend, allowing users to turn on/off line series. 
  8.  .showYAxis(true) //Show the y-axis 
  9.  .showXAxis(true) //Show the x-axis 
  10.  ; 
  11.  chart.xAxis //Chart x-axis settings 
  12.  .axisLabel('Time (ms)') 
  13.  .tickFormat(d3.format(',r')); 
  14.  chart.yAxis //Chart y-axis settings 
  15.  .axisLabel('Voltage (v)') 
  16.  .tickFormat(d3.format('.02f')); 
  17.  /* Done setting the chart up? Time to render it!*/ 
  18.  var myData = sinAndCos(); //You need data... 
  19.  d3.select('#chart svg') //Select the  element you want to render the chart in.  
  20.  .datum(myData) //Populate the  element with chart data... 
  21.  .call(chart); //Finally, render the chart! 
  22.  //Update the chart when window resizes. 
  23.  nv.utils.windowResize(function() { chart.update() }); 
  24.  return chart; 
  25. }); 
  26. /************************************** 
  27.  * Simple test data generator 
  28.  */ 
  29. function sinAndCos() { 
  30.  var sin = [],sin2 = [], 
  31.  cos = []; 
  32.  //Data is represented as an array of {x,y} pairs. 
  33.  for (var i = 0; i < 100; i++) { 
  34.  sin.push({x: i, y: Math.sin(i/10)}); 
  35.  sin2.push({x: i, y: Math.sin(i/10) *0.25 + 0.5}); 
  36.  cos.push({x: i, y: .5 * Math.cos(i/10)}); 
  37.  } 
  38.  //Line chart data should be sent as an array of series objects. 
  39.  return [ 
  40.  { 
  41.  values: sin, //values - represents the array of {x,y} data points 
  42.  key: 'Sine Wave', //key - the name of the series. 
  43.  color: '#ff7f0e' //color - optional: choose your own line color. 
  44.  }, 
  45.  { 
  46.  values: cos, 
  47.  key: 'Cosine Wave', 
  48.  color: '#2ca02c' 
  49.  }, 
  50.  { 
  51.  values: sin2, 
  52.  key: 'Another sine wave', 
  53.  color: '#7777ff', 
  54.  area: true //area - set to true if you want this line to turn into a filled area chart. 
  55.  } 
  56.  ]; 
  57. }
 

C3.js

與 TauCharts 相同,C3.js 也是一個(gè)非常有效的基于 D3 的圖表可視化庫(kù)。另外,C3.js 允許用戶創(chuàng)建可定制的具有個(gè)人風(fēng)格的類。

C3.js 看起來(lái)是個(gè)比較難的庫(kù),但是一旦掌握了 C3.js 技巧,就能得心應(yīng)手的使用了。

有了 C3.js 圖表庫(kù),即使在***次渲染之后,用戶也可以通過(guò)創(chuàng)建回調(diào)來(lái)更新圖表。C3.js 也允許用戶為自己的 Web 應(yīng)用程序創(chuàng)建可復(fù)用的圖表,從而減少工作量。

使用 npm 安裝 C3.js 圖表庫(kù):

npm install c3

C3.js 繪制組合圖的代碼示例:

  
 
 
 
  1. var chart = c3.generate({ 
  2. data: {  
  3. columns: [  
  4. ['data1', 30, 20, 50, 40, 60, 50],  
  5. ['data2', 200, 130, 90, 240, 130, 220],  
  6. ['data3', 300, 200, 160, 400, 250, 250],  
  7. ['data4', 200, 130, 90, 240, 130, 220],  
  8. ['data5', 130, 120, 150, 140, 160, 150],  
  9. ['data6', 90, 70, 20, 50, 60, 120],  
  10. ],  
  11. type: 'bar',  
  12. types: {  
  13. data3: 'spline',  
  14. data4: 'line',  
  15. data6: 'area',  
  16. },  
  17. groups: [  
  18. ['data1','data2']  
  19. ]  
  20. }  
  21. });
 

TauCharts

TauCharts 是最靈活的 JavaScript 圖表庫(kù)之一。它是基于 D3 創(chuàng)建的,是一個(gè)以數(shù)據(jù)為中心的 JavaScript 圖表庫(kù),可以改進(jìn)數(shù)據(jù)可視化的效果。

TauCharts 十分靈活,訪問(wèn)其 API 也十分輕松。TauCharts 為用戶提供了無(wú)縫映射和可視化的數(shù)據(jù),使用 TauCharts 能夠設(shè)計(jì)出十分美觀的數(shù)據(jù)界面。同時(shí),TauCharts 也和易于學(xué)習(xí)。

通過(guò) npm 安裝 TauCharts:

  
 
 
 
  1. npm install taucharts 

TauCharts 繪制水平線的代碼示例:

  
 
 
 
  1. var defData = [ 
  2. {"team": "d", "cycleTime": 1, "effort": 1, "count": 1, "priority": "low"}, {  
  3. "team": "d",  
  4. "cycleTime": 2,  
  5. "effort": 2,  
  6. "count": 5,  
  7. "priority": "low"  
  8. }, {"team": "d", "cycleTime": 3, "effort": 3, "count": 8, "priority": "medium"}, {  
  9. "team": "d",  
  10. "cycleTime": 4,  
  11. "effort": 4,  
  12. "count": 3,  
  13. "priority": "high"  
  14. }, {"team": "l", "cycleTime": 2, "effort": 1, "count": 1, "priority": "low"}, {  
  15. "team": "l",  
  16. "cycleTime": 3,  
  17. "effort": 2,  
  18. "count": 5,  
  19. "priority": "low"  
  20. }, {"team": "l", "cycleTime": 4, "effort": 3, "count": 8, "priority": "medium"}, {  
  21. "team": "l",  
  22. "cycleTime": 5,  
  23. "effort": 4,  
  24. "count": 3,  
  25. "priority": "high"  
  26. },  
  27. {"team": "k", "cycleTime": 2, "effort": 4, "count": 1, "priority": "low"}, {  
  28. "team": "k",  
  29. "cycleTime": 3,  
  30. "effort": 5,  
  31. "count": 5,  
  32. "priority": "low"  
  33. }, {"team": "k", "cycleTime": 4, "effort": 6, "count": 8, "priority": "medium"}, {  
  34. "team": "k",  
  35. "cycleTime": 5,  
  36. "effort": 8,  
  37. "count": 3,  
  38. "priority": "high"  
  39. }];  
  40. var chart = new tauCharts.Chart({  
  41. data: defData,  
  42. type: 'horizontalBar',  
  43. x: 'effort',  
  44. y: 'team',  
  45. color:'priority'  
  46. });  
  47. chart.renderTo('#bar');
 

Recharts

ReCharts 是一個(gè)使用 React 構(gòu)建的,基于 D3 的圖表庫(kù)。

使用 ReCharts,用戶可以在 React Web 應(yīng)用程序中無(wú)縫地編寫圖表。

Recharts 非常輕巧,并使用 SVG 元素來(lái)創(chuàng)建很奇特的圖表。

使用 npm 安裝 Recharts:

  
 
 
 
  1. npm install recharts 

Recharts 沒(méi)有冗長(zhǎng)的文檔,它很直接。當(dāng)你遇到困難時(shí),使用 Recharts 可以很容易找到解決方案。

Recharts 創(chuàng)建自定義內(nèi)容樹圖的代碼示例:

  
 
 
 
  1. const {Treemap} = Recharts; 
  2. const data = [  
  3. {  
  4. name: 'axis',  
  5. children: [  
  6. { name: 'Axes', size: 1302 },  
  7. { name: 'Axis', size: 24593 },  
  8. { name: 'AxisGridLine', size: 652 },  
  9. { name: 'AxisLabel', size: 636 },  
  10. { name: 'CartesianAxes', size: 6703 },  
  11. ],  
  12. },  
  13. {  
  14. name: 'controls',  
  15. children: [  
  16. { name: 'AnchorControl', size: 2138 },  
  17. { name: 'ClickControl', size: 3824 },  
  18. { name: 'Control', size: 1353 },  
  19. { name: 'ControlList', size: 4665 },  
  20. { name: 'DragControl', size: 2649 },  
  21. { name: 'ExpandControl', size: 2832 },  
  22. { name: 'HoverControl', size: 4896 },  
  23. { name: 'IControl', size: 763 },  
  24. { name: 'PanZoomControl', size: 5222 },  
  25. { name: 'SelectionControl', size: 7862 },  
  26. { name: 'TooltipControl', size: 8435 },  
  27. ],  
  28. },  
  29. {  
  30. name: 'data',  
  31. children: [  
  32. { name: 'Data', size: 20544 },  
  33. { name: 'DataList', size: 19788 },  
  34. { name: 'DataSprite', size: 10349 },  
  35. { name: 'EdgeSprite', size: 3301 },  
  36. { name: 'NodeSprite', size: 19382 },  
  37. {  
  38. name: 'render',  
  39. children: [  
  40. { name: 'ArrowType', size: 698 },  
  41. { name: 'EdgeRenderer', size: 5569 },  
  42. { name: 'IRenderer', size: 353 },  
  43. { name: 'ShapeRenderer', size: 2247 },  
  44. ],  
  45. },  
  46. { name: 'ScaleBinding', size: 11275 },  
  47. { name: 'Tree', size: 7147 },  
  48. { name: 'TreeBuilder', size: 9930 },  
  49. ],  
  50. },  
  51. {  
  52. name: 'layout',  
  53. children: [  
  54. { name: 'AxisLayout', size: 6725 },  
  55. { name: 'BundledEdgeRouter', size: 3727 },  
  56. { name: 'CircleLayout', size: 9317 },  
  57. { name: 'CirclePackingLayout', size: 12003 },  
  58. { name: 'DendrogramLayout', size: 4853 },  
  59. { name: 'ForceDirectedLayout', size: 8411 },  
  60. { name: 'IcicleTreeLayout', size: 4864 },  
  61. { name: 'IndentedTreeLayout', size: 3174 },  
  62. { name: 'Layout', size: 7881 },  
  63. { name: 'NodeLinkTreeLayout', size: 12870 },  
  64. { name: 'PieLayout', size: 2728 },  
  65. { name: 'RadialTreeLayout', size: 12348 },  
  66. { name: 'RandomLayout', size: 870 },  
  67. { name: 'StackedAreaLayout', size: 9121 },  
  68. { name: 'TreeMapLayout', size: 9191 },  
  69. ],  
  70. },  
  71. { name: 'Operator', size: 2490 },  
  72. { name: 'OperatorList', size: 5248 },  
  73. { name: 'OperatorSequence', size: 4190 },  
  74. { name: 'OperatorSwitch', size: 2581 },  
  75. { name: 'SortOperator', size: 2023 },  
  76. ],  
  77. ];  
  78. const COLORS = ['#8889DD', '#9597E4', '#8DC77B', '#A5D297', '#E2CF45', '#F8C12D'];  
  79. const CustomizedContent = React.createClass({  
  80. render() {  
  81. const { root, depth, x, y, width, height, index, payload, colors, rank, name } = this.props;  
  82. return (  
  83.   
  84. x={x}  
  85. y={y}  
  86. width={width}  
  87. height={height}  
  88. style={{  
  89. fill: depth < 2 ? colors[Math.floor(index / root.children.length * 6)] : 'none',  
  90. stroke: '#fff',  
  91. strokeWidth: 2 / (depth + 1e-10),  
  92. strokeOpacity: 1 / (depth + 1e-10),  
  93. }}  
  94. />  
  95. {  
  96. depth === 1 ?  
  97. x={x + width / 2}  
  98. y={y + height / 2 + 7}  
  99. textAnchor="middle"  
  100. fill="#fff"  
  101. fontSize={14}  
  102. >  
  103. {name}  
  104.   
  105. : null  
  106. }  
  107. {  
  108. depth === 1 ?  
  109. x={x + 4}  
  110. y={y + 18}  
  111. fill="#fff"  
  112. fontSize={16}  
  113. fillOpacity={0.9}  
  114. >  
  115. {index + 1}  
  116.   
  117. : null  
  118. }  
  119.   
  120. );  
  121. }  
  122. });  
  123. const SimpleTreemap = React.createClass({  
  124. render () {  
  125. return (  
  126. width={400}  
  127. height={200}  
  128. data={data}  
  129. dataKey="size"  
  130. ratio={4/3}  
  131. stroke="#fff"  
  132. fill="#8884d8"  
  133. content={}  
  134. />  
  135. );  
  136. }  
  137. })  
  138. ReactDOM.render(  
  139. ,  
  140. document.getElementById('container')  
  141. );
 

Flot


目前,jQuery 已經(jīng)成為 Web 開發(fā)人員非常重要的工具。有了 Flot.js,前端設(shè)計(jì)也變得更加容易。

Flot.js 是 JavaScript 庫(kù)中較為古老的圖表庫(kù)之一。盡管如此,F(xiàn)lot.js 也不會(huì)因?yàn)槔L制折線圖、餅圖、條形圖、面積圖、甚至堆疊圖表而降低其性能。

Flot.js 有一個(gè)很完善的文檔。當(dāng)用戶遇到困難時(shí),可以很容易地找到解決辦法。Flot.js 也支持舊版本的瀏覽器。

可以選擇不使用 npm 來(lái)安裝 Flot.js,而是在 HTML5 中包含 jQuery 和 JavaScript 文件。

Flot.js 的基本用法代碼示例:

  
 
 
 
  1. $(function () { 
  2.  var d1 = []; 
  3.  for (var i = 0; i < 14; i += 0.5) 
  4.  d1.push([i, Math.sin(i)]); 
  5.  var d2 =[[0, 3], [4, 8], [8, 5], [9, 13]]; 
  6.  // a null signifies separate line segments 
  7.  var d3 =[[0, 12], [7, 12], null, [7, 2.5], [12, 2.5]]; 
  8.  $.plot($("#placeholder"), [ d1, d2, d3 ]); 
  9. });
 

JavaScript 開發(fā)工具推薦

SpreadJS 純前端表格控件是基于 HTML5 的 JavaScript 電子表格和網(wǎng)格功能控件,提供了完備的公式引擎、排序、過(guò)濾、輸入控件、數(shù)據(jù)可視化、Excel 導(dǎo)入/導(dǎo)出等功能,適用于 .NET、Java 和移動(dòng)端等各平臺(tái)在線編輯類 Excel 功能的表格程序開發(fā)。

總結(jié)

以上介紹的 JavaScript 庫(kù)都是高質(zhì)量的圖表庫(kù)。但是在學(xué)習(xí)這些庫(kù)的過(guò)程中,可能會(huì)因?yàn)閷W(xué)習(xí)曲線陡峭或是缺乏學(xué)習(xí)資料而遇到困難,一種很好的方案是將這些庫(kù)結(jié)合起來(lái)使用。***也歡迎大家補(bǔ)充更多的 JavaScript 圖表庫(kù)。

責(zé)任編輯:龐桂玉
來(lái)源: 今日頭條 前端 Javascript 圖表庫(kù)


本文名稱:前端開發(fā)者常用的9個(gè)JavaScript圖表庫(kù)
文章鏈接:http://www.dlmjj.cn/article/dhcsjss.html