各データポイントの色をそれぞれ変更することはできません。条件に基づいてASP.NET Chart DataPointをカスタマイズします
数値が< = 10の場合、色は赤色になります。 number> 10の場合、色は緑色になります。
コード(私はループのための、しかし無駄にその後、foreachループを使用してみました...) だけで利用可能//をご覧ください:
ChartClass.Series.Clear();
BedsBLL get = new BedsBLL();
int A1Available = get.countAvailA1();
int A1Alloted = get.countUnavailA1();
int B1Available = get.countAvailB1();
int B1Alloted = get.countUnavailB1();
int B2Available = get.countAvailB2();
int B2Alloted = get.countUnavailB2();
int C1Available = get.countAvailC1();
int C1Alloted = get.countUnavailC1();
//Available
Series seriesAvail = ChartClass.Series.Add("SeriesAvailable");
seriesAvail.Color = Color.ForestGreen;
seriesAvail.LegendText = "Available Number of Beds";
String[] classArrAvail = { "A1", "B1", "B2", "C1" };
int[] countAvailable = { A1Available, B1Available, B2Available, C1Available };
ChartClass.Series["SeriesAvailable"].Points.DataBindXY(classArrAvail, countAvailable);
ChartClass.Series["SeriesAvailable"].YValuesPerPoint = 2;
foreach (DataPoint pt in ChartClass.Series["SeriesAvailable"].Points)
{
if (pt.XValue <= 10)
{
pt.Color = Color.Red;
}
else if (pt.XValue > 10)
{
pt.Color = Color.ForestGreen;
}
/*for (int i = 0; i < countAvailable.Length; i++)
{
if (countAvailable[i] <= 10)
{
pt.Color = Color.Red;
}
else if (countAvailable[i] > 10)
{
pt.Color = Color.ForestGreen;
}
}*/
}
//Alloted
Series seriesAlloted = ChartClass.Series.Add("SeriesAlloted");
seriesAlloted.Color = Color.Gray;
seriesAlloted.LegendText = "Alloted Number of Beds";
String[] classArrAlloted = { "A1", "B1", "B2", "C1" };
int[] countAlloted = { A1Alloted, B1Alloted, B2Alloted, C1Alloted };
ChartClass.Series["SeriesAlloted"].Points.DataBindXY(classArrAlloted, countAlloted);
デザイナー:
<asp:Chart ID="ChartClass" runat="server" Height="350px" Width="380px">
<Series>
<asp:Series Name="SeriesAvailable" IsValueShownAsLabel="True" LabelAngle="-90" Font="Microsoft Sans Serif, 12pt" Legend="LegendClass" ChartArea="ChartAreaClass" ChartType="StackedColumn">
<SmartLabelStyle Enabled="false" />
</asp:Series>
<asp:Series Name="SeriesAlloted" IsValueShownAsLabel="True" LabelAngle="-90" Font="Microsoft Sans Serif, 12pt" Legend="LegendClass" ChartArea="ChartAreaClass" ChartType="StackedColumn">
<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>
が、私は同様の質問に答え、取ります一見[ここ](http://stackoverflow.com/questions/3880) 7084/how-to-customize-asp-net-chart-databound-to-sqldatasource/38811378#38811378)。 – jsanalytics
しかし、なぜ私はランダムが必要ですか?鉱山は、その条件を満たすデータポイントの色を変更する条件に基づいています。申し訳ありませんが、失われています..私はasp.netを開始して以来、今まで2つのチャートを行っているだけです... @jstreet – domster
あなたは、ランダムが必要です。 'PreRender'イベントを処理するだけです。しかし、今私は明示的にあなたのデータポイントを追加する(私のサンプルのようなデータベースからではない)ので、おそらくそれを必要としない....参照してください....デバッガを使用して、色を変更するループが正しく動作していることを確認する。 – jsanalytics