如何在asp.net的图表控件中添加不同颜色的列 [英] How to add different color of column in chart control in asp.net
问题描述
我正在对 ASP.NET图表控件进行编码,并且图表代码如下所示。
I am doing coding of ASP.NET chart control and chart code is as per below
<asp:Chart ID="Chart1" runat="server" Width="450px" Height="200px" BackColor="211, 223, 240"
Palette="None" BorderLineStyle="Solid" BackGradientEndColor="White" BackGradientType="TopBottom"
BorderlineWidth="2" BorderlineColor="26, 59, 105" EnableViewState="True">
<Series>
<asp:Series Name="Series1" BorderColor="180, 26, 59, 105" Color="Blue" BorderWidth="2"
ShadowColor="254, 0, 0, 0" ChartType="Column" ShadowOffset="1" MarkerSize="8" MarkerStyle="Diamond">
<EmptyPointStyle BackGradientStyle="Center" />
</asp:Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea" BorderColor="64, 64, 64, 64" BorderDashStyle="Solid"
BackSecondaryColor="White" BackColor="64, 165, 191, 228" ShadowColor="Transparent"
BackGradientStyle="TopBottom">
<AxisY LineColor="#eb9c28">
<MajorGrid LineColor="64, 64, 64, 64"></MajorGrid>
</AxisY>
<AxisX LineColor="64, 64, 64, 64" TextOrientation="Horizontal" IsStartedFromZero="true">
<LabelStyle Format="dd/MM/yyyy" IntervalType="Days" Interval="1"></LabelStyle>
<MajorGrid LineColor="64, 64, 64, 64"></MajorGrid>
</AxisX>
</asp:ChartArea>
</ChartAreas>
<BorderSkin SkinStyle="Emboss" />
</asp:Chart>
我已经按照以下方式从后面的代码绑定了此图表控件
and i have bind this chart control from code behind as per below
Chart1.DataSource = dt;
Chart1.Series["Series1"].XValueMember = "UTC";
Chart1.Series["Series1"].YValueMembers = "Value";
Chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Minutes;
Chart1.ChartAreas[0].AxisX.Interval = 5;
Chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm:ss";
现在 dt(数据源)中还有第3列,名为严重性,值将为 a, b, c ...
Now in dt (datasource) there is also 3rd column named as Severity and values will be "a", "b","c" ...
现在,我想根据需要自定义列颜色此值表示
Now i would like to customize column color as per this value, means
如果a->红色
if a -> Red
b->蓝色
c->像这样的绿色
请帮助我
预先感谢。
推荐答案
您可以通过设置
Chart1.Series[0].YValuesPerPoint = 2;
现在,对于列,它仅使用一个值,但在另一列中,您可以绑定对应的值
Now for Column it would be using only one value but in the other column you could bind a value corresponding to a,b,c as say 1,2,3 and now bind this to the series.
Chart1.Series["Series1"].YValueMembers = "Value,intvalueforcolor";
要应用颜色,您将必须遍历系列中的点,例如
To apply the colors you will have to loop through the points in the series like
foreach (DataPoint pt in Chart1.Series[0].Points)
{
pt.YValues[1] // this will be your value depending upon which you could set the color
//pt.Color = ...
}
这篇关于如何在asp.net的图表控件中添加不同颜色的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!