TeeChart数据源作为该系列的Excel文件

时间:2014-06-30 13:21:42

标签: activex teechart

任何人都可以帮我解决如何从excel中读取Teechart中的系列数据(X,Y和系列Naane)。我尝试使用CSeriesTextSource读取Data.xls文件,但没有成功。

由于 阿克沙伊

1 个答案:

答案 0 :(得分:1)

您可以从xls创建csv,然后使用CSeriesTextSource导入此csv,如发布的示例here中所示。

编辑:这是该帖子的代码:

Private Sub Form_Load()    
  TChart1.Aspect.View3D = False  
  TChart1.Axis.Bottom.Labels.Style = 2 'talValue
  TChart1.Axis.Left.Logarithmic = True

  TChart1.AddSeries scFastLine
  TChart1.AddSeries scFastLine
  TChart1.AddSeries scPoint
  TChart1.AddSeries scPoint
  TChart1.Series(0).XValues.DateTime = True
  TChart1.Series(1).XValues.DateTime = True
  TChart1.Series(2).XValues.DateTime = True
  TChart1.Series(3).XValues.DateTime = True

  With SeriesTextSource1
    .FileName = "C:\tmp\Data.csv"
    .HeaderLines = 1
    .FieldSeparator = ";"

    .Series = TChart1.Series(0)
    .AddField "X", 1
    .AddField "Y", 2
    .Active = True

    .Series = TChart1.Series(1)
    .AddField "X", 3
    .AddField "Y", 4
    .Active = True

' This works with v2012, but with v8
'    .Series = TChart1.Series(2)
'    .AddField "X", 5
'    .AddField "Y", 6
'    .Active = True
'
'    .Series = TChart1.Series(3)
'    .AddField "X", 7
'    .AddField "Y", 8
'    .Active = True
  End With

' I add the values manually in v8:
  TChart1.Series(2).AddXY CDate("10/11/2003"), 0, "", clTeeColor
  TChart1.Series(3).AddXY CDate("01/02/1999"), 231.48, "", clTeeColor
End Sub

Private Sub TChart1_OnClick()
  Caption = "Min: " + FormatDateTime(TChart1.Axis.Bottom.MinVisibleSeriesValue(True, 0)) + ", Max: " + FormatDateTime(TChart1.Axis.Bottom.MaxVisibleSeriesValue(True, 0))
End Sub

您可以下载包含测试here的数据的csv。