Let me give you a final result:
To achieve the effect, first prepare a picture, height of 25pixel, width of 1 to 3pixel gradient picture. can download here.
Also prepare the data:
Dictionary<int, int> Datas
{
get
{
dictionary<int, int> d = new Dictionary<int, int> ();
D.add (1, km);
D.add (2,);
D.add (3);
return D;
}
}
OK, the data is ready, put three label controls in ASPX, of course you can display in other controls or tags, one thing to note is width= "300", which is the gradient picture at 100% width:
<asp:label id= "Label1" runat= "Server" style= "MARGIN:3PX;" text= "" Width= "borderwidth=" 1 ></asp:label><br/> <asp:label id= "
Label2" runat= "Server" Style= "MARGIN:3PX;" text= "" Width= "borderwidth=" 1 ></asp:label><br/> <asp:label id= "
Label3" runat= "Server" Style= "MARGIN:3PX;" Text= "" "Width=" borderwidth= "1" ></asp:label><br/>
To display the data on a label:
protected void Page_Load (object sender, EventArgs e)
{
data_binding ();
}
private void Data_binding ()
{
int totals = m;
foreach (Keyvaluepair<int, int> kvp in Datas)
{
double rate = kvp. Value/(double) totals;
Double width = rate *;
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");
The above is asp.net to realize the gradient picture method, hope to be helpful to everybody's study.