本文介绍了ASP.NET StackedColumn图表-轴故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am building an Asp.net Stacked Column chart.

这是它的外观:

这是它的外观:

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

Ignore the numbers on the chart but look at the X axis - Why does it give me 1148,1153, 1163 when they do not appear in the data.

这是我的数据:

以下是代码:

   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)

任何帮助将不胜感激。谢谢!

Any help would be appreciated. Thank you!

推荐答案

DataBindCrossTable 可以以最少的编码工作来尽力而为从你那里。但是,如果您对默认行为不满意,则必须显式自定义它。在您的特定情况下,您想为数据点分配自定义标签:

DataBindCrossTable does the best job it can with minimal coding effort required from you. But if you are not happy with the default behavior then you have to explicitly customize it. In your particular case, you want to assign custom labels to your data points:

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);
    }
}

这篇关于ASP.NET StackedColumn图表-轴故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 22:03