gpt4 book ai didi

c# - 如何使用 C# 将其他系列添加到 Excel 图表

转载 作者:行者123 更新时间:2023-11-30 14:57:10 25 4
gpt4 key购买 nike

enter image description here我正在尝试向显示 CPU 阈值的图表添加一个额外的数据系列,我可以获得范围并创建没有阈值的图表,但我不知道如何将阈值添加到图表。我需要创建另一个图表对象吗?我可以使用现有的并添加新的范围吗?

Threshold values

您如何创建图表? -- 请参阅下面的代码。此图表是否已在excel 文件中创建,您要修改excel 文件中的图表?是的,图表已经在 Excel 文件中。

Excel.ChartObjects sCPUChart; Excel.ChartObject sCPUChartObjects;

        sCPUChart = sDBSheet.ChartObjects(Type.Missing);
sCPUChartObjects = sCPUChart.Add(49, 15, 360, 215);

Excel.Chart sChartCPU;

sChartCPU = sCPUChartObjects.Chart;
sChartCPU.SetSourceData(cpuChartRange, Missing.Value);
sChartCPU.ChartWizard(Source: cpuChartRange, Gallery: Excel.XlChartType.xlLine, Format: 2, HasLegend: true);
sChartCPU.Location(Excel.XlChartLocation.xlLocationAsObject, sDBSheet.Name);

//CPU Chart Axis
Excel.Axis xSChartCPUAxis;
xSChartCPUAxis = sChartCPU.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary);


Excel.Axis ySChartCPUAxis;
ySChartCPUAxis = syChartCPU.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary);
ySChartCPUAxis.HasMajorGridlines = true;
ySChartCPUAxis.MaximumScaleIsAuto = true;

//Set Summary CPU Series
Excel.Series sCPUSeries = sChartCPU.SeriesCollection(1);
sCPUSeries.Name = "CPU";


//-------
// this is where I am having my issue
//I don't know how to add the threshold line to the graph with the existing graph being displayed

//sChartCPU.set_HasAxis(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlSecondary, true);
//summaryChartCPU.SetSourceData(summaryMemThreshold, Type.Missing); -- things break
//-------
I have now done the following:


Excel.SeriesCollection threshold = sChartCPU.sseriesCollection();
Excel.Series line = threshold.NewSeries();
line.Formula = "=SERIES(Summ!$D$54,Summ!$C$55:$C$56,Summ!$D$55:$D$56)";
line.ChartType = Excel.XlChartType.xLScatterLinesNoMarkers;


when the threshold line is created I have the following

with new series

我在单元格 D54 中的值 - 阈值

  C55 = 0
C56 = 1
D55 = 75
D56 = 75

我不知道如何删除图表中出现的 2 个附加轴如果我注释掉 line.ChartType,那么轴是正确的,但我只得到一个阈值数据点??我不明白为什么。

最佳答案

var series = (SeriesCollection) yourChart.SeriesCollection();
var line = series.NewSeries();

line.Name = "CPU Threshhold";
//line.Values = ...;
//line.XValues = ...;

//formatting

关于c# - 如何使用 C# 将其他系列添加到 Excel 图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21234085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com