连接 Word 图表中的空点

Connect Empty Points in Word Chart

我正在使用 Word Interop 在我的 C# 应用程序中创建图表。在此图中,我有一些空数据点。如何以编程方式连接空点?我想实现 this 但内部代码。任何人都可以帮助我吗?谢谢

编辑: 这是代码

Dictionary<DateTime, Dictionary<string, decimal>> visuData = new Dictionary<DateTime, Dictionary<string, decimal>>(); 
string startTime = null;
string endTime = null;          //Variablen für die Zeitspanne, aus der Versuchsdaten abgerufen werden sollen
query = "SELECT MIN(Starttime) AS Starttime, MAX(Starttime) AS Endtime FROM dbo.Table WHERE ID = " + checkBox.Text;
con = new SqlConnection(mtecConnectionString);
cmd = new SqlCommand(query, con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
    startTime = reader.GetDateTime(0).ToString("yyyy-MM-dd hh:mm:ss.fff");
    endTime = reader.GetDateTime(1).ToString("yyyy-MM-dd hh:mm:ss.fff");
}
con.Close();            //Zeitspanne bestimmen
if (startTime == null || endTime == null)
    return;         //Falls keine Daten vorliegen, wird die Methode beendet

List<string> variables = new List<string>();
query = "SELECT ...";
con = new SqlConnection(@"...");
cmd = new SqlCommand(query, con);           //Abfrage für Versuchsdaten und Verbindung zur Datenbank setzen
con.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
    if (visuData.ContainsKey(reader.GetDateTime(2)))
    {
        visuData[reader.GetDateTime(2)].Add(reader.GetString(0), 
        reader.GetDecimal(1));
    }
    else
    {
        visuData.Add(reader.GetDateTime(2), new Dictionary<string, decimal>());
        visuData[reader.GetDateTime(2)].Add(reader.GetString(0), 
        reader.GetDecimal(1));
    }

    if (!variables.Contains(reader.GetString(0)))
        variables.Add(reader.GetString(0));
}
 con.Close();

Chart chart = document.InlineShapes.AddChart2(-1, XlChartType.xlLineMarkers, paragraph.Range).Chart;
Microsoft.Office.Interop.Excel.Workbook excelWorkbook = chart.ChartData.Workbook;
excelWorkbook.Application.WindowState = Microsoft.Office.Interop.Excel.XlWindowState.xlMinimized;
Microsoft.Office.Interop.Excel.Worksheet excelWorksheet = excelWorkbook.Worksheets[1];

for(int j = 2; j < variables.Count + 2; j++)
{
    excelWorksheet.Cells[1, j].Value = variables[j - 2];
}
int rowIndex = 2;
foreach (DateTime moment in visuData.Keys)
{
    excelWorksheet.Cells[rowIndex, 1].Value = moment.ToString("HH:mm:ss");
    for(int j = 2; j < variables.Count + 2; j++)
    {
        if (visuData[moment].ContainsKey(variables[j - 2]))
            excelWorksheet.Cells[rowIndex, j].Value = visuData[moment][variables[j - 2]];
    }
    rowIndex += 1;
}

chart.ChartTitle.Text = "Batch ID " + checkBox.Text;
chart.Refresh();
excelWorkbook.Close(Type.Missing, Type.Missing, Type.Missing);

我想随时间显示一些变量。所以我创建了一个以时间戳为键的字典,另一个字典为值。在第二个字典中,我使用键来识别变量和值来获取值。

这看起来像: 2021-12-02 08:00:00 --> Var 1 : 1 2021-12-02 08:00:00 --> Var 2 : 2

2021-12-02 08:05:00 --> 变量 1:3 2021-12-02 08:05:00 --> Var 3 : 4

实际输出是,我在创建的 word 文档中有一个图表。对于 Var 3,上午 8 点显示的值为 0,但我不想在上午 8 点显示 var 3 的任何值。与 Var 2 相同...

希望现在更清楚了

我自己找到了解决方案。

我在刷新图表填充线之前添加:

chart.DisplayBlanksAs = Microsoft.Office.Interop.Word.XlDisplayBlanksAs.xlInterpolated;