0

当我绘制条形图时,一些项目没有在 X 轴上正确绘制,而等效的 Y 轴很好。

我的用户控件有以下代码,

<asp:Chart ID="Chart1" runat="server" Width="850px" Height="600px">
    <Series>
        <asp:series Name="Series1"></asp:series>
    </Series>
    <ChartAreas>
        <asp:ChartArea Name="ChartArea1">
        </asp:ChartArea>
    </ChartAreas>
</asp:Chart>

填充数据表的代码,

protected DataTable GetGroupExperienceData(PickerEntity pickerEntity)
{
    DataTable table;
    table = new DataTable();

    table.Columns.Add("Participant", typeof(string));
    table.Columns.Add("Experience", typeof(Int32));
    table.Columns.Add("Question", typeof(string));

    DataRow row;                    

    if (collListItems2.Count > 0 && collListItems2 != null)
    {
        for (int i = 0; i < collListItems2.Count; i++)
        {
            row = table.NewRow();

            row["Participant"] = user.Name;

            SPFieldLookupValue lpkFieldQName = new SPFieldLookupValue(itemRep["SurveyQuestion"].ToString());
            string lkpQNameVal = lpkFieldQName.LookupValue;

            row["Question"] = lkpQNameVal;

            SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("(Error)", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ">" + row["Question"].ToString(), "");

            if (itemRep["Experience"] !=null)
            {
                row["Experience"] = itemRep["Experience"];
            }
            else
            {
                row["Experience"] = Convert.ToInt32("0");
            }

            table.Rows.Add(row);
        }
    }

    return dt;
}

最后图表绘制代码,

protected void DrawExperienceChart(DataTable dt)
{
    Chart1.Series["Series1"].ChartType = SeriesChartType.Bar;
    Chart1.Series["Series1"]["DrawingStyle"] = "Emboss";
    Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false;
    Chart1.Series["Series1"].IsValueShownAsLabel = true;
    Chart1.DataSource = dt;
    Chart1.Series["Series1"].XValueMember = "Question";
    Chart1.Series["Series1"].YValueMembers = "Experience";
    Chart1.DataBind();
}

所有这些函数都是通过单击按钮调用的,

protected void btnGetReport_Click(object sender, EventArgs e)
{
    DataTable dt =  GetGroupExperienceData(pickerEntity);

    DrawExperienceChart(dt);   
}

这是输出,X asix 上缺少许多“问题”数据,但在 Y 轴上很好地绘制了等效的“经验”。

在此处输入图像描述

我想可能是数据没有进入数据表,但数据表有我可以看到的数据SPDiagnosticsService.Local.WriteTrace()

在此处输入图像描述

4

1 回答 1

0

很简单,有一个设置必须启用才能查看所有标签,否则图表控件将隐藏大部分标签。

Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1;
于 2013-03-21T16:03:23.663 回答