本文整理汇总了C#中Microsoft.Office.Interop.Excel.ChartObjects方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.Office.Interop.Excel.ChartObjects方法的具体用法?C# Microsoft.Office.Interop.Excel.ChartObjects怎么用?C# Microsoft.Office.Interop.Excel.ChartObjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Excel
的用法示例。
在下文中一共展示了Microsoft.Office.Interop.Excel.ChartObjects方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateGraph
private void CreateGraph(IScriptWorker CurrentScriptWorker, Excel.Worksheet xlWorkSheet, int RowCounter, int ColumnCounterForNamesOfTests)
{
Excel.Range chartRange;
Excel.ChartObjects xlCharts = (Excel.ChartObjects)xlWorkSheet.ChartObjects(Type.Missing);
Excel.ChartObject myChart = xlCharts.Add(100, 200, 800, 350);
Excel.Chart chartPage = myChart.Chart;
chartRange = xlWorkSheet.get_Range((Excel.Range)xlWorkSheet.Cells[1, 1], (Excel.Range)xlWorkSheet.Cells[RowCounter - 1, ColumnCounterForNamesOfTests - 1]);
chartPage.ChartWizard(Source: chartRange,
Gallery: Excel.XlChartType.xlColumnClustered,
Title: (string)CurrentScriptWorker.GetLabName(),
CategoryTitle: (string)CurrentScriptWorker.GetValueSeparator(),
ValueTitle: (string)CurrentScriptWorker.GetValueType());
}
示例2: createInnerChart
/// <summary>
/// 给工作表添加一个图表
/// </summary>
/// <param name="firstRange">数据工作表</param>
/// <param name="xData">x轴数据区域:格式A1:A14</param>
/// <param name="ydata">y轴数据区域:格式B1:E14</param>
/// <param name="chartName">图标名称</param>
/// <param name="xname">y轴名称</param>
/// <param name="yname">y轴名称</param>
/// <param name="chartType">图表类型</param>
public static void createInnerChart(Excel.Worksheet dataSheet, List<ChartStuct> charts, string chartName,string categoryName)
{
Excel.ChartObjects ChartObjects = (Excel.ChartObjects)dataSheet.ChartObjects(Missing.Value);
if (charts.Count < 1) return;//无数不处理
//绘制第一维图表
Excel.Range firstRange = charts[0].dataRange;
Excel.XlChartType chartType = charts[0].chartType;
string yname = charts[0].yname;
int cols = 0;
foreach (ChartStuct chartStuct in charts)
{
cols += chartStuct.dataRange.Columns.Count;
}
Excel.ChartObject chartObject = ChartObjects.Add(cols * 60, 30, 800, 350);
chartObject.Chart.ChartWizard(firstRange, chartType, Missing.Value, Excel.XlRowCol.xlColumns, 1, 1, true, chartName, categoryName, yname, Missing.Value);
chartObject.Chart.ChartArea.ClearFormats();
chartObject.Chart.ChartType = chartType;
chartObject.Chart.ChartArea.Fill.BackColor.SchemeColor = 2;//整个图表区背景
//Console.WriteLine(chartObject.Chart.ChartArea.Fill.ForeColor.SchemeColor);
//Console.WriteLine(chartObject.Chart.ChartArea.Fill.ForeColor.RGB);
chartObject.Chart.ChartArea.Fill.ForeColor.SchemeColor = 2;
//Console.WriteLine(chartObject.Chart.ChartArea.Fill.ForeColor.RGB);
//Console.WriteLine(chartObject.Chart.PlotArea.Interior.ColorIndex);
//chartObject.Chart.PlotArea.Interior.PatternColorIndex = 19;
chartObject.Chart.PlotArea.Interior.ColorIndex = 2;//图例区域背景
Excel.Axis firstAxis = (Excel.Axis)chartObject.Chart.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary);
firstAxis.HasMajorGridlines = true;//不显示横向网格线
//firstAxis.HasTickLabels = false;
//chartObject.Chart.PlotArea.Border.LineStyle = Excel.XlLineStyle.xlLineStyleNone;//设置绘图区边框线条
Excel.SeriesCollection seriesCollection = (Excel.SeriesCollection)chartObject.Chart.SeriesCollection(Type.Missing);
//xlSeries1.Fill=Microsoft.Office.Interop.Excel.ChartFillFormat.
if (seriesCollection.Count > 0)
{
Excel.Series seires1 = (Excel.Series)seriesCollection.Item(1);//具体数据图表区颜色
//seires1.Fill.BackColor.SchemeColor = 18;
seires1.Fill.ForeColor.SchemeColor = 46;
seires1.MarkerForegroundColorIndex = Excel.XlColorIndex.xlColorIndexNone;
seires1.HasLeaderLines = false;
}
int sc = seriesCollection.Count;
//绘制第二维图表
//修改第一维图表的各个序列的图例,这里有个bug,会用最后的标题覆盖前面的
// for (int i = 0; i < charts[0].seriesTitles.Length; i++)
//{
//string stitle = charts[0].seriesTitles[i];
//Excel.Series tmpSeires = (Excel.Series)seriesCollection.Item(1);
//tmpSeires.Name = stitle;
//}
//绘制第二个图表,多维这里设置 当有图表类型为XlChartType.xl3DColumn或其他3d效果时,抛 xlSeries.AxisGroup = Excel.XlAxisGroup.xlSecondary;异常
for (int i = 1; i < charts.Count; i++)
{
ChartStuct cs = charts[i];
string stitle = cs.seriesTitles[0];
Excel.Series xlSeries = (Excel.Series)seriesCollection.NewSeries();
xlSeries.Name = stitle;
xlSeries.HasLeaderLines = true;
xlSeries.Fill.ForeColor.SchemeColor = 46;
//xlSeries.Has3DEffect = true;
//xlSeries.HasDataLabels = true;
try
{
xlSeries.AxisGroup = Excel.XlAxisGroup.xlSecondary;
}
catch (Exception eee){
Console.WriteLine(eee.Message);
}
xlSeries.ChartType = cs.chartType;
xlSeries.Values = cs.dataRange;
Excel.Axis valueAxis = (Excel.Axis)chartObject.Chart.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlSecondary);
valueAxis.HasTitle = true;
valueAxis.AxisTitle.Text = cs.yname;
}
}
示例3: Draw
public TreemapChart Draw(Excel.Worksheet sheet)
{
Excel.ChartObjects cos = sheet.ChartObjects();
Excel.ChartObject co = cos.Add(ChartArea.Left, ChartArea.Top, ChartArea.Width, ChartArea.Height);
Chart = co.Chart;
Draw();
return this;
}
示例4: BuildMetricHistogram
private static void BuildMetricHistogram(Excel.Worksheet xlWorkSheet, object misValue, string lowBorder, string highBorder, double left,
double top, double width, double height)
{
try
{
Excel.Range chartRange;
Excel.ChartObjects xlCharts = (Excel.ChartObjects)xlWorkSheet.ChartObjects(Type.Missing);
Excel.ChartObject chart = (Excel.ChartObject)xlCharts.Add(left, top, width, height);
Excel.Chart chartPage = chart.Chart;
chartRange = xlWorkSheet.get_Range(lowBorder, highBorder);
chartPage.SetSourceData(chartRange, misValue);
chartPage.ChartType = Excel.XlChartType.xlColumnClustered;
}
catch (Exception exception)
{
throw exception;
}
}
示例5: displayExcel
/// <summary>
/// Заполнение данными и построение графиокв
/// </summary>
/// <param name="oWS">excel work sheet obj</param>
/// <param name="min">minimal value</param>
/// <param name="max">maximal value</param>
private void displayExcel(Excel._Worksheet oWS, double min, double max)
{
// Вводим основные данные для графика
Excel.ChartObjects xlCharts = (Excel.ChartObjects)oWS.ChartObjects(Type.Missing);
Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(110, 0, 350, 250);
Excel.Chart chart = myChart.Chart;
chart.ChartType = Excel.XlChartType.xlXYScatterSmooth;
Excel.SeriesCollection seriesCollection = (Excel.SeriesCollection)chart.SeriesCollection(Type.Missing);
Excel.Series series = seriesCollection.NewSeries();
series.XValues = oWS.get_Range("A1", "A1000");
series.Values = oWS.get_Range("B1", "B1000");
// Создаём оси
Excel.Axis Yaxis = (Excel.Axis)chart.Axes(
Excel.XlAxisType.xlValue,
Excel.XlAxisGroup.xlPrimary);
Excel.Axis Xaxis;
Xaxis = (Excel.Axis)chart.Axes(
Excel.XlAxisType.xlCategory,
Excel.XlAxisGroup.xlPrimary);
// Подписи осей
Yaxis.HasTitle = true;
Yaxis.AxisTitle.Text = "Какое-то имя";
Xaxis.HasTitle = true;
Xaxis.AxisTitle.Text = "Время, с";
//Масштаб осей
Yaxis.ScaleType = Excel.XlScaleType.xlScaleLogarithmic;
Yaxis.MinimumScale = min / 1.5;
Yaxis.MaximumScale = max * 2;
Xaxis.ScaleType = Excel.XlScaleType.xlScaleLogarithmic;
}