gpt4 book ai didi

c# - ASP.NET 堆积柱形图 - 轴故障

转载 作者:行者123 更新时间:2023-11-30 17:33:52 25 4
gpt4 key购买 nike

我正在构建一个 Asp.net 堆积柱形图。

这是它的样子:

Chart Image

它应该是这样的:

Goal Chart Image

忽略图表上的数字,但查看 X 轴 - 当它们未出现在数据中时,为什么它会给我 1148、1153、1163。

这是我的数据:

Data Image

代码如下:

   Dim chart As New Chart
chart.ID = "Chart1"

Dim chartareas As New ChartArea
chart.ChartAreas.Add(chartareas)

chart.DataBindCrossTable(DtFinalRecords.DefaultView, "OutcomeScore", "TermID", "RecordsPerGroup", "Label=RecordsPerGroup")




chart.ChartAreas(0).AxisX.MajorGrid.Enabled = False
chart.ChartAreas(0).AxisY.MajorGrid.Enabled = False


For Each cs As Series In chart.Series
cs.ChartType = SeriesChartType.StackedColumn
Next

pnlcharts.Controls.Add(chart)

如有任何帮助,我们将不胜感激。谢谢你!

最佳答案

DataBindCrossTable 尽其所能,您只需付出最少的编码工作。但是,如果您对默认行为不满意,则必须显式自定义它。在您的特定情况下,您希望为数据点分配自定义标签:

protected void Page_Load(object sender, EventArgs e)
{
Chart1.Palette = ChartColorPalette.None;
Chart1.PaletteCustomColors = new Color[] { ColorTranslator.FromHtml("#DF5B59"), ColorTranslator.FromHtml("#E0D773 "), ColorTranslator.FromHtml("#8AAC53"), ColorTranslator.FromHtml("#6A843F") };

Chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
Chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
Chart1.ChartAreas[0].AxisX.Interval = 1;

var rows = from row in dt.AsEnumerable() select row.Field<int>("OutcomeScore");

Chart1.Series.Clear();

foreach (int i in rows.Distinct())
Chart1.Series.Add(new Series { Name = i.ToString(), ChartType = SeriesChartType.StackedColumn });

foreach (DataRow dr in dt.Rows)
{
DataPoint dp = new DataPoint();
dp.AxisLabel = dr["TermID"].ToString();
dp.Label = dr["RecordsPerGroup"].ToString();
dp.XValue = (int)dr["TermID"];
dp.YValues[0] = (int)dr["RecordsPerGroup"];

string name = dr["OutcomeScore"].ToString();
Chart1.Series[name].Points.Add(dp);
}
}

enter image description here

关于c# - ASP.NET 堆积柱形图 - 轴故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43211145/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com