自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Charts.css:一個數(shù)據(jù)可視化開源神器

開發(fā) 前端
Charts.css 是用于數(shù)據(jù)可視化的開源 CSS 框架,幫助用戶理解數(shù)據(jù),幫助開發(fā)人員使用簡單的 CSS 類將數(shù)據(jù)轉(zhuǎn)換為漂亮的圖表。

 簡介

數(shù)據(jù)可視化可以改善用戶體驗,因為數(shù)據(jù)的圖形表示通常更容易理解??梢暬瘞椭罱K用戶理解數(shù)據(jù),而Charts.css可以幫助開發(fā)人員使用簡單的CSS類將其數(shù)據(jù)轉(zhuǎn)換為精美的圖形。

Charts.css是用于數(shù)據(jù)可視化的新的開源框架。它用CSS框架代替了傳統(tǒng)的JS圖表庫。

傳統(tǒng)的圖表庫往往使用JS渲染數(shù)據(jù),嚴(yán)重依賴JS,大型的JS庫通常會影響網(wǎng)站性能,搜索引擎也無法讀取存儲在JS對象中的數(shù)據(jù)。而Charts.css是現(xiàn)代的CSS框架,原始數(shù)據(jù)是HTML的一部分,使其對搜索引擎和可見;使用CSS不需要渲染,可以提高性能。

它支持多種數(shù)據(jù)展示形式,包括面形圖、條形圖、柱形圖、折線圖、多數(shù)據(jù)集面形圖、多數(shù)據(jù)集條形圖、多數(shù)據(jù)集及柱形圖、多數(shù)據(jù)集折線圖、百分比柱形圖、堆積柱形圖、3D條形效果、3D傾斜效果等。

Charts.css具有以下特點:

  •  純前端,使用HTML和CSS構(gòu)建
  •  簡單易用
  •  個性化定制,可以按照自己的方式設(shè)置圖標(biāo)樣式
  •  開源,可以修改代碼
  •  響應(yīng)式
  •  支持多種圖表類型

項目地址是:

https://github.com/ChartsCSS/charts.css

安裝

  •  使用jsdelivr CDN引入: 
  1. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/charts.css/dist/charts.min.css"> 
  •  使用unpkg CDN引入: 
  1. <link rel="stylesheet" href="https://unpkg.com/charts.css/dist/charts.min.css"> 
  •  使用npm安裝: 
  1. npm install charts.css 
  •  使用yarn安裝: 
  1. yarn add charts.css 
  •  源碼引入: 
  1. // 從這里下載源碼壓縮包  
  2. https://github.com/ChartsCSS/charts.css/releases  
  3. // 把charts.min.css復(fù)制到自己的項目中并引入  
  4. <link rel="stylesheet" href="path/to/your/charts.min.css"> 

簡單使用

Charts.css將原始數(shù)據(jù)放在HTML的table元素中,從而使其對搜索引擎可見。

數(shù)據(jù)表示例: 

  1. <table>  
  2.   <caption> 2016 Summer Olympics Medal Table </caption>  
  3.   <thead>  
  4.     <tr>  
  5.       <th scope="col"> Country </th>  
  6.       <th scope="col"> Gold </th>  
  7.       <th scope="col"> Silver </th>  
  8.       <th scope="col"> Bronze </th>  
  9.     </tr>  
  10.   </thead>  
  11.   <tbody>  
  12.     <tr>  
  13.       <th scope="row"> USA </th>  
  14.       <td> 46 </td>  
  15.       <td> 37 </td>  
  16.       <td> 38 </td>  
  17.     </tr>  
  18.     <tr>  
  19.       <th scope="row"> GBR </th>  
  20.       <td> 27 </td>  
  21.       <td> 23 </td>  
  22.       <td> 17 </td>  
  23.     </tr>  
  24.     <tr>  
  25.       <th scope="row"> CHN </th>  
  26.       <td> 26 </td>  
  27.       <td> 18 </td>  
  28.       <td> 26 </td>  
  29.     </tr>  
  30.   </tbody>  
  31. </table> 

將數(shù)據(jù)顯示為圖表,只需要將.charts-css添加到table元素的class屬性中,并選擇一種圖表類型即可。

單一數(shù)據(jù)集,是指table中的每個tr元素只有一個td子元素: 

  1. <tr>  
  2.   <td> Data </td>  
  3. </tr> 

多數(shù)據(jù)集,是指table中的每個tr元素有多個td子元素: 

  1. <tr>  
  2.   <td> Data </td>  
  3.   <td> Data </td>  
  4.   <td> Data </td>  
  5. </tr> 
  •  條形圖: 
  1. // 單數(shù)據(jù)集條形圖  
  2. <table class="charts-css bar">  
  3.   ...  
  4. </table>  
  5. // 多數(shù)據(jù)集條形圖  
  6. <table class="charts-css bar multiple"> 
  7.   ...  
  8. </table> 

  •  柱形圖: 
  1. // 單數(shù)據(jù)集柱形圖  
  2. <table class="charts-css column">  
  3.   ...  
  4. </table>  
  5. // 多數(shù)據(jù)集柱形圖  
  6. <table class="charts-css column multiple">  
  7.   ...  
  8. </table> 

每一種類型的圖表其實都是類似的代碼(也體現(xiàn)出了這個庫的易用性),這里不再重復(fù),詳細(xì)參考官網(wǎng)。

個性化

要添加自定義CSS,只需在table標(biāo)簽中添加id或class即可: 

  1. // html  
  2. <table class="charts-css ..." id="my-chart">  
  3.   ...  
  4. </table>  
  5. // css  
  6. #my-chart {  
  7.   ...  

最佳實踐應(yīng)該是將圖表類型添加到選擇器,這樣一來CSS就只適用于該圖表類型,其他類型圖表不會受影響: 

  1. /* Custom style applies only on bar charts */  
  2. #my-chart.bar {  
  3.   ...  
  4.  
  5. /* Other style applies only on pie charts */  
  6. #my-chart.pie {  
  7.   ...  
  •  3D效果:可以使用CSSbox-shadow屬性 
  1. #custom-effect tbody td {  
  2.   margin-inline-start: 10px;  
  3.   margin-inline-end: 20px;  
  4.   box-shadow:  
  5.     1px -1px 1px lightgrey,  
  6.     2px -2px 1px lightgrey,  
  7.     3px -3px 1px lightgrey,  
  8.     4px -4px 1px lightgrey,  
  9.     5px -5px 1px lightgrey,  
  10.     6px -6px 1px lightgrey,  
  11.     7px -7px 1px lightgrey,  
  12.     8px -8px 1px lightgrey,  
  13.     9px -9px 1px lightgrey,  
  14.     10px -10px 1px lightgrey;  

  •  運動效果:當(dāng)用戶將鼠標(biāo)懸停在數(shù)據(jù)項上時,背景顏色將發(fā)生變化 
  1. #motion-effect tr {  
  2.   transition-duration: 0.3s;  
  3.  
  4. #motion-effect tr:hover {  
  5.   background-color: rgba(0, 0, 0, 0.2);  
  6.  
  7. #motion-effect tr:hover th {  
  8.   background-color: rgba(0, 0, 0, 0.4);  
  9.   color: #fff;  
  •  動畫效果:th元素每3秒旋轉(zhuǎn)一次 
  1. #animations-example-2 th {  
  2.   animation: spin-labels 3s linear infinite;  
  3.  
  4. @keyframes spin-labels {  
  5.   0%   { transform: rotateX(   0deg ); }  
  6.   40%  { transform: rotateX( 360deg ); }  
  7.   100% { transform: rotateX( 360deg ); } 
  8.  

 

責(zé)任編輯:龐桂玉 來源: 前端大全
相關(guān)推薦

2017-06-19 08:30:35

大數(shù)據(jù)數(shù)據(jù)可視化報表

2020-03-09 09:20:32

開源技術(shù) 軟件

2025-02-25 11:14:39

2023-04-14 08:21:55

2017-07-25 13:42:00

大數(shù)據(jù)可視化工具

2020-04-10 14:20:47

算法可視化Github

2022-02-23 09:50:52

PythonEchartspyecharts

2024-01-29 13:02:00

數(shù)據(jù)可視化庫數(shù)組

2019-09-27 09:12:18

開源數(shù)據(jù)可視化大數(shù)據(jù)

2021-06-24 13:00:35

微軟開源可視化

2021-03-31 13:28:17

開源工具Python編程語言

2009-06-26 13:11:33

可視化開發(fā)JSFNetBeans

2021-11-04 09:10:22

CSS 技巧代碼重構(gòu)

2021-07-02 14:07:00

可視化Plotly漏斗圖

2020-03-11 14:39:26

數(shù)據(jù)可視化地圖可視化地理信息

2019-10-14 15:51:40

可視化技術(shù)微軟數(shù)據(jù)庫

2024-07-05 11:08:21

2023-02-21 08:02:09

可視化工具圖表

2019-10-10 17:40:54

數(shù)據(jù)科學(xué)可視化繪圖

2015-11-11 11:10:40

數(shù)據(jù)可視化開源工具
點贊
收藏

51CTO技術(shù)棧公眾號