![](/img/trans.png)
[英]Custom legend text on ASP.NET Chart bound by DataBindCrossTable
[英]Add Custom Legend with Color Indicator ASP.NET Chart
直接..請問如何在圖表底部創建自定義圖例?
傳說會.. 紅色床位低
設計器中的代碼:
<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);
圖片:
我嘗試過在線查找和搜索。 似乎找不到我正在尋找的任何可靠來源或解決方案。
大多數解決方案都將圖例添加到特定系列中。
我對ms-chart相當陌生...
感謝任何幫助。 謝謝..
構建系列后,添加以下代碼:
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.