热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ASP。网断续柱图表-轴的麻烦-ASP.NETStackedColumnchart-AxisTrouble

IambuildinganAsp.netStackedColumnchart.我正在构建一个Asp.net堆叠的列图。Hereishowitlooks:下面是它的样子

I am building an Asp.net Stacked Column chart.

我正在构建一个Asp.net堆叠的列图。

Here is how it looks :

下面是它的样子:

Chart Image

Here is how it should look :

它应该是这样的:

Goal Chart Image

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.

忽略图表上的数字,看看X轴——为什么它给出1148,1153,1163,当它们不出现在数据中。

Here is my Data :

以下是我的数据:

Data Image

Here is the code:

这是代码:

   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!

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

1 个解决方案

#1


1  

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:

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("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


推荐阅读
author-avatar
有海的地方最美_171
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有