掃二維碼與項(xiàng)目經(jīng)理溝通
我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流
最終效果:

實(shí)現(xiàn)效果,首先準(zhǔn)備一張圖片,高度為25pixel,寬度為1至3pixel漸變的圖片??梢赃@里下載。
還要準(zhǔn)備數(shù)據(jù):
- Dictionary
Datas - {
- get
- {
- Dictionary
d = new Dictionary (); - d.Add(1, 35);
- d.Add(2, 45);
- d.Add(3, 20);
- return d;
- }
- }
ok,數(shù)據(jù)準(zhǔn)備完了,在aspx里放三個(gè)Label控件,當(dāng)然你可以顯示在其它控件或是標(biāo)簽中,有一點(diǎn)要注意的是Width="300",它是漸變圖片在100%的寬度:
把數(shù)據(jù)顯示于Label上:
- protected void Page_Load(object sender, EventArgs e)
- {
- Data_Binding();
- }
- private void Data_Binding()
- {
- int totals = 100;
- foreach (KeyValuePair
kvp in Datas) - {
- double rate = kvp.Value / (double)totals;
- double width = rate * 300;
- switch (kvp.Key)
- {
- case 1:
- this.Label1.Text = GradientImage(width, rate);
- break;
- case 2:
- this.Label2.Text = GradientImage(width, rate);
- break;
- case 3:
- this.Label3.Text = GradientImage(width, rate);
- break;
- }
- }
- }
- private string GradientImage(double width, double rate)
- {
- return "
" + rate.ToString("p");
- }

我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流