2012-12-20 66 views
0

我很難在登打士圖表上繪製系列數據。它似乎無法正確綁定DateTime值。無法將DateTime系列與登打士圖表綁定

這裏是分鐘圖代碼:

public static void GenerateMultiSeriesChartImage<T,U>(List<ChartData<T,U>> chartData, string chartTitle, 
    string xAxisTitle, string yAxisTitle, string xAxisValue, string yAxisValue, string chartFileName) 
{ 
    Dundas.Charting.WebControl.Chart chart = new Dundas.Charting.WebControl.Chart(); 
    // Setting some chart properties 

    Dundas.Charting.WebControl.Legend legend = new Dundas.Charting.WebControl.Legend(); 

    // I'm setting the legend properties    
    chart.Legends.Add(legend); 

    // Setting the border skin 
    Dundas.Charting.WebControl.Title title = new Dundas.Charting.WebControl.Title(); 
    title.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold); 

    // Set custom chart title 
    title.Text = chartTitle; 
    chart.Titles.Add(title); 

    int cnt = 1; 
    foreach (ChartData<T,U> dataRecord in chartData) 
    { 
     Dundas.Charting.WebControl.Series series = new Dundas.Charting.WebControl.Series(); 

     series.Name = dataRecord.SeriesName; 
     series.BorderColor = System.Drawing.ColorTranslator.FromHtml("#646464"); 
     series.BorderWidth = 2; 
     series.Type = Dundas.Charting.WebControl.SeriesChartType.Line; 
     series.MarkerBorderColor = System.Drawing.ColorTranslator.FromHtml("#646464"); 
     series.ShadowOffset = 1; 

     // Set X & Y axis ValueMembers 
     series.ValueMembersY = yAxisValue; 
     series.ValueMemberX = xAxisValue; 

     series.XValueType = dataRecord.XValueType; 
     series.YValueType = dataRecord.YValueType; 

     series.Points.DataBindXY(dataRecord.XAxisValues, xAxisTitle, dataRecord.YAxisValues, yAxisTitle); 
     chart.Series.Add(series); 
     cnt++; 
    } 

    Dundas.Charting.WebControl.ChartArea chartArea = new Dundas.Charting.WebControl.ChartArea(); 
    chartArea.BackColor = System.Drawing.Color.Lavender; 
    chartArea.Name = "Default"; 
    chartArea.ShadowOffset = 2; 
    chartArea.AxisY.Title = yAxisTitle; 
    chartArea.AxisY.MajorGrid.LineColor = System.Drawing.Color.LightSteelBlue; 
    chartArea.AxisY.MajorGrid.LineStyle = Dundas.Charting.WebControl.ChartDashStyle.Dash; 
    chartArea.AxisX.Title = xAxisTitle; 
    chartArea.AxisX.MajorGrid.LineColor = System.Drawing.Color.LightSteelBlue; 
    chartArea.AxisX.MajorGrid.LineStyle = Dundas.Charting.WebControl.ChartDashStyle.Dash; 
    chartArea.Area3DStyle.WallWidth = 0; 
    chart.ChartAreas.Add(chartArea); 

    chart.Save("C:/charts/" + chartFileName, Dundas.Charting.WebControl.ChartImageFormat.Png); 
} 

的ChartData類只是包含我的一系列的輔助和回合他們一些元數據:

public class ChartData<X,Y> 
{ 
    public List<X> XAxisValues { get; private set; } 
    public List<Y> YAxisValues { get; private set; } 
    public ChartValueTypes XValueType { get; private set; } 
    public ChartValueTypes YValueType { get; private set; } 
    public string SeriesName { get; private set; } 

    public ChartData(string seriesName, ChartValueTypes xValueType, ChartValueTypes yValueType) 
    { 
     XAxisValues = new List<X>(); 
     YAxisValues = new List<Y>(); 
     SeriesName = seriesName; 
     XValueType = xValueType; 
     YValueType = yValueType; 
    } 

    public ChartData(string seriesName, X[] xAxisValues, Y[] yAxisValues, ChartValueTypes xValueType, ChartValueTypes yValueType) 
    { 
     XAxisValues = new List<X>(xAxisValues); 
     YAxisValues = new List<Y>(yAxisValues); 
     SeriesName = seriesName; 

     XValueType = xValueType; 
     YValueType = yValueType; 
    } 
} 

你可以看到XValues的內容和YValues集合在這裏:https://docs.google.com/spreadsheet/pub?key=0AtV11BVzMrGYdDdrdjY1WC1wc09aV0E3cmo3VkpJSEE&output=html

而且我得到以下圖表(請注意日期是完全的錯誤):

10 rows

XValueTypeDateTimeYValueTypeInt

series.XValueType = dataRecord.XValueType; // DateTime 
series.YValueType = dataRecord.YValueType; // Int 

事情變得更糟,當我嘗試圖表60個值:

enter image description here

回答

0

只是基金會d出什麼問題:xAxisValue應該是「日期」,我把它當作「日」。