简体   繁体   English

Microsoft图表控件轴标题显示不正确

[英]Microsoft Chart Control Axis Titles not displaying properly

I am having problems getting the XAxis to display the correct values in my chart control. 我在使XAxis在图表控件中显示正确的值时遇到问题。 Below is how I am generating each series to be displayed. 以下是我如何生成要显示的每个系列。 I would like the XAxis to display the DataType value from s.DataType: 我希望XAxis从s.DataType显示DataType值:

 foreach (SummaryData s in summaryData)
    {
        System.Web.UI.DataVisualization.Charting.Series series = new System.Web.UI.DataVisualization.Charting.Series(s.DataType);
        series.ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Column;            
        DataPoint dp = new DataPoint();            
        dp.Name = s.DataType;            
        dp.SetValueY(s.Total);
        dp.SetCustomProperty("DataType", s.DataType);
        series.XValueMember = "DataType";                        
        series.Points.Add(dp);
        msBarVertLegRight.Series.Add(series);            
    }
    msBarVertLegRight.DataBind();     

The corect value is displayed and the correct name in the Legend, but I'm not exactly sure how to set the XAxis value. 将显示corect值,并在图例中显示正确的名称,但是我不确定如何设置XAxis值。

JH JH

Looks like you're trying to use databinding (which is what the XValueMember is for) and add points one by one. 看起来您正在尝试使用数据绑定(这是XValueMember目的)并一一添加点。 You can do one or the other. 您可以做一个或另一个。 You could use databinding like so (approximately): 您可以像这样使用数据绑定(大约):

series.XValueMember = "DataType";
series.YValueMember = "ThePropertyWithY";
series.DataSource = s;
series.DataBind();

or you could set each point individually: 或者您可以分别设置每个点:

System.Web.UI.DataVisualization.Charting.Series series = new System.Web.UI.DataVisualization.Charting.Series("mySeries");
series.ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Column;

foreach (SummaryData s in summaryData)
{                
    series.AddXY(s.DataType, s.Total);
}

I'm not sure why you had each SummaryData.DataType being its own series; 我不确定为什么每个SummaryData.DataType都是自己的系列;为什么? if that is needed, add that back in, but from the code you posted it didn't seem necessary. 如果需要,请重新添加,但是从您发布的代码中似乎没有必要。

When databinding, any changes to your underlying data (the SummaryData objects) will be reflected in your chart automatically; 进行数据绑定时,对基础数据( SummaryData对象)的任何更改将自动反映在图表中。 if you add points individually, you need to handle updates to your chart manually. 如果单独添加点,则需要手动处理图表的更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM