2017-02-05 8 views
1

똑바로 .. 내 차트 맨 아래에 사용자 지정 범례를 만드는 방법을 묻는 질문이 있습니까?색 표시기 ASP.NET 차트로 사용자 정의 범례 추가

전설이 될 것입니다 .. 디자이너 레드 낮은 침대 수

코드 :

   <asp:Chart ID="ChartClass" Visible="false" runat="server" Height="500px" Width="720px"> 
       <Series> 
        <asp:Series Name="SeriesAvailableClass" IsValueShownAsLabel="True" LabelAngle="-90" Font="Microsoft Sans Serif, 12pt" Legend="LegendClass" ChartArea="ChartAreaClass" ChartType="Column"> 
         <SmartLabelStyle Enabled="false" /> 
        </asp:Series> 
        <asp:Series Name="SeriesAllotedClass" IsValueShownAsLabel="True" LabelAngle="-90" Font="Microsoft Sans Serif, 12pt" Legend="LegendClass" ChartArea="ChartAreaClass" ChartType="Column"> 
         <SmartLabelStyle Enabled="false"/> 
        </asp:Series> 
       </Series> 
       <ChartAreas> 
        <asp:ChartArea Name="ChartAreaClass"> 
         <AxisX Title="Class"> 
          <MajorGrid Enabled="false" /> 
         </AxisX> 
         <AxisY Title="Number of Beds"> 
          <MajorGrid Enabled="false" /> 
         </AxisY> 
        </asp:ChartArea> 
       </ChartAreas> 
       <Legends> 
        <asp:Legend Docking="Bottom" Name="LegendClass"></asp:Legend> 
       </Legends> 
       <Titles> 
        <asp:Title Name="TitleChart" Font="Microsoft Sans Serif, 15pt, style=Bold" Text="Beds Statistics Summary (Class)" Alignment="TopCenter"></asp:Title> 
       </Titles> 
       </asp:Chart> 

코드가 백 엔드 :

 Series seriesAvail = ChartClass.Series.Add("SeriesAvailableClass"); 
     seriesAvail.Color = Color.ForestGreen; 
     seriesAvail.LegendText = "Available Number of Beds"; 
     seriesAvail.IsValueShownAsLabel = true; 
     seriesAvail.LabelAngle = 0; 
     seriesAvail.Font = new Font("Microsoft Sans Serif", 8); 
     seriesAvail.SmartLabelStyle.Enabled = false; 


     String[] classArrAvail = { "A1", "B1", "B2", "C1" }; 
     int[] countAvailable = { A1Available, B1Available, B2Available, C1Available }; 

     ChartClass.Series["SeriesAvailableClass"].Points.DataBindXY(classArrAvail, countAvailable); 

     foreach (DataPoint pt in ChartClass.Series["SeriesAvailableClass"].Points) 
     { 
      if (pt.YValues[0] < 10) 
      { 
       pt.Color = Color.Red; 
      } 
      else if (pt.YValues[0] >= 10) 
      { 
       pt.Color = Color.ForestGreen; 
      } 

     } 


     Series seriesAlloted = ChartClass.Series.Add("SeriesAllotedClass"); 
     seriesAlloted.Color = Color.SkyBlue; 
     seriesAlloted.LegendText = "Alloted Number of Beds"; 
     seriesAlloted.IsValueShownAsLabel = true; 
     seriesAlloted.LabelAngle = 0; 
     seriesAlloted.Font = new Font("Microsoft Sans Serif", 8); 
     seriesAlloted.SmartLabelStyle.Enabled = true; 

     String[] classArrAlloted = { "A1", "B1", "B2", "C1" }; 
     int[] countAlloted = { A1Alloted, B1Alloted, B2Alloted, C1Alloted }; 

     ChartClass.Series["SeriesAllotedClass"].Points.DataBindXY(classArrAlloted, countAlloted); 

이미지 :

enter image description here

온라인으로 검색하고 검색해 보았습니다. 신뢰할 수있는 출처 나 해결책을 찾지 못하는 것 같습니다.

대부분의 솔루션에는 특정 계열에 범례가 추가되어 있습니다.

저는 MS- 차트를 처음 접하게되었습니다 ...

감사합니다.

답변

1

당신이 당신의 시리즈를 빌드 한 후 다음 코드를 추가합니다 .. 주셔서 감사합니다 :

LegendItem item1 = new LegendItem(); 
    item1.ImageStyle = LegendImageStyle.Rectangle; 
    item1.Color = Color.Red; 
    item1.BorderColor = Color.Red; 
    item1.Cells.Add(LegendCellType.SeriesSymbol, "", ContentAlignment.MiddleCenter); 
    item1.Cells.Add(LegendCellType.Text, "Low Bed Number", ContentAlignment.MiddleLeft); 
    ChartClass.Legends[0].CustomItems.Add(item1); 

enter image description here

+0

당신에게 너무 많은 jstreet 감사합니다! 아직 시도해 보지 못했지만 효과가 있다고 확신합니다. 미안 해요 내 프로젝트에 다른 물건으로 바빴어요 .. 정말 고마워요! – domster

+0

서두르지 말고 시간을들이십시오. – jsanalytics

+0

작동합니다! 정말 고맙습니다!! – domster