2009-11-05 5 views
0

asp net 웹 페이지에 키워드 클라우드를 추가해야합니다! 누구든지 나에게 그것을 할 수있는 가장 좋은 방법을 제안 할 수 있습니까? C#을 사용하여 구현 된 몇 가지 작업 예제가 있지만이를 수행 할 다른 방법이 있는지 알고 싶습니다! 좋은 제안은 정말 감사하겠습니다! 사전 :ASP.NET에서 키워드 클라우드 추가하기 페이지

답변

0

이 코드를 사용하여 시도 할 수 있습니다 감사드립니다 .. 나는 어느 정도 짐작

 Int32 rank, minVal, maxVal, scale, s; 

     minVal = st.GetMinRank(); 
     maxVal = st.GetMaxRank(); 
     scale = (maxVal - minVal)/6; 
     rank = Convert.ToInt32(yourRankValue that is stored in your DB); 

     if (scale == 0) 
      s = 0; 
     else 
      s = (rank - minVal)/scale; 

     if (s == 0) 
     { 
      lblSTName.Font.Size = FontUnit.Smaller; 
     } 
     else if (s == 1) 
     { 
      lblSTName.Font.Size = FontUnit.Small; 
     } 
     else if (s == 2) 
     { 
      lblSTName.Font.Size = FontUnit.Medium; 
     } 
     else if (s == 3) 
     { 
      lblSTName.Font.Size = FontUnit.Large; 
     } 
     else if (s == 4) 
     { 
      lblSTName.Font.Size = FontUnit.Larger; 
     } 
     else if (s >= 5) 
     { 
      lblSTName.Font.Size = FontUnit.Larger; 
      lblSTName.Font.Bold = true; 
     } 
0

는 대답은 방법과 장소 키워드 데이터가 저장되는에 따라 달라집니다.

Photos-TagsPhotos-Tags http://www.doodle.co.uk/UserFiles/Image/Photos-Tags.png

이 그래서 사진이 TagsPhotos 테이블을 통해 태그에 연결되어 있습니다 :

나는 다음과 같은 테이블이있는 데이터베이스가 있습니다.

protected void Page_Load(object sender, EventArgs e) { 

    // "zhpCtx" is a LINQ to SQL data context. 
    // "TagCloud" is a Panel control. 

    // Select a list of tags and a count of how often they appear in TagsPhotos 
    var tagDensity = from t in zhpCtx.siteContent_Tags 
       join tp in zhpCtx.siteContent_TagsPhotos 
        on t.TagID equals tp.TagID 
       group t by new { t.TagID, t.TagText } into g 
       where g.Count() > 0 
       orderby g.Key.TagText 
       select new { g.Key.TagID, g.Key.TagText, NumTags = g.Count() }; 

    if (null != tagDensity && tagDensity.Count() > 0) { 
    // We have some tags, get the lowest number of counts greater than 0, and 
    // the highest to give our range. 
    int? min = tagDensity.Min(t => t.NumTags); 
    int? max = tagDensity.Max(t => t.NumTags); 

    // Loop through each tag 
    foreach (var tag in tagDensity) { 
     // Create a new HyperLink control to take the user to a given tag 
     // Include the tag count in the list for accessibility. 
     // Could probably move it to the title attribute. 
     // Build the link however suits. 
     HyperLink tagLink = new HyperLink { 
       NavigateUrl = string.Format("Photos.aspx?TagID={0}", tag.TagID), 
       Text = string.Format("{0} ({1})", tag.TagText, tag.NumTags) }; 

     // Adjust the font-size of the tag link - calling getPercentage. 
     // This will adjust the size based on the baseline font size for the 
     // container 
     tagLink.Style.Add("font-size", 
     string.Format("{0}%", 
         getPercentageSize((int)max, (int)min, tag.NumTags))); 

     // Add the HyperLink to the Panel. 
     TagCloud.Controls.Add(tagLink); 
     // Add a LiteralControl with a comma and a space. 
     TagCloud.Controls.Add(new LiteralControl(", ")); 
    } 

    // Remove the last separator control from the Panel. 
    TagCloud.Controls.RemoveAt(TagCloud.Controls.Count - 1); 
    } else { 
    // Hide the tag cloud panel 
    TagCloud.Visible = false; 
    } 
} 

private int getPercentageSize(int max, int min, int score) { 
    // Ensure we've got a sensible number 
    if (min < 1) { 
     min = 1; 
    } 

    double spread = max - min; 

    if (spread == 0) { 
     spread = 1; 
    } 

    // Setup sensible bounds for the font sizes 
    int minSize = 80; 
    int maxSize = 200; 

    // Step ensures that our least used keyword is 80% and our 
    // most used is 200% 
    double step = (maxSize - minSize)/spread; 

    return (int)(minSize + ((score - min) * step)); 
} 
:

나는 다음 내 키워드 구름을 생성하기 위해 다음과 같은 방법을 사용

관련 문제