Ejemplo n.º 1
0
        void addTrendlineOption(string text, EventHandler handler)
        {
            OptionInfo option = new OptionInfo(text, handler);

            Trendlines.Add(option);
            this.AddOption(option);
        }
Ejemplo n.º 2
0
        // Function that creates the plot
        public static void plotChart(string columnTitle)
        {
            Range  chartRange;
            object misValue = System.Reflection.Missing.Value;

            // Creates the chart
            ChartObjects xlCharts = (ChartObjects)ExcelExecutions.xlWorksheet.ChartObjects(Type.Missing);
            ChartObject  myChart  = xlCharts.Add(250, 50, 600, 350);
            Chart        xlChart  = myChart.Chart;

            xlChart.ChartType = XlChartType.xlXYScatter;

            // Gets the range for the column title
            Range XcolumnTitleLocation = findCell(ExcelExecutions.xTitle);
            Range YcolumnTitleLocation = findCell(columnTitle);

            // The title for the x- and y-axis
            Axis xAxis = xlChart.Axes(XlAxisType.xlCategory, XlAxisGroup.xlPrimary) as Axis;
            Axis yAxis = xlChart.Axes(XlAxisType.xlValue, XlAxisGroup.xlPrimary) as Axis;

            xAxis.HasTitle       = true;
            yAxis.HasTitle       = true;
            xAxis.AxisTitle.Text = XcolumnTitleLocation.Value;
            yAxis.AxisTitle.Text = YcolumnTitleLocation.Value;

            // The values for the chart
            string xColumnPrefix = ExcelExecutions.columnNames[XcolumnTitleLocation.Column - 1];
            string yColumnPrefix = ExcelExecutions.columnNames[YcolumnTitleLocation.Column - 1];
            Range  xValues       = ExcelExecutions.xlWorksheet.Range[xColumnPrefix + "2", (xColumnPrefix + ExcelExecutions.xlRange.Rows.Count.ToString())];
            Range  yvalues       = ExcelExecutions.xlWorksheet.Range[yColumnPrefix + "2", (yColumnPrefix + ExcelExecutions.xlRange.Rows.Count.ToString())];

            // Assigns the value to the chart
            SeriesCollection seriesCollection = xlChart.SeriesCollection();
            Series           pointPlot        = seriesCollection.NewSeries();

            pointPlot.XValues = xValues;
            pointPlot.Name    = columnTitle;
            pointPlot.Values  = yvalues;

            // Creates trendline(regression)
            Trendlines trendlines       = (Trendlines)pointPlot.Trendlines(Type.Missing);
            Trendline  linearRegression = trendlines.Add(XlTrendlineType.xlLinear);

            linearRegression.DisplayEquation = true;
            linearRegression.DisplayRSquared = true;


            saveChart(xlChart, pointPlot.Name);
        }