I am using excel to draw charts from c#, but i need the chart to be one series related to each other not two series (when i select a range that has two columns of data)
can any one help:
xla.Visible = true;
Workbook wb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet ws = (Worksheet)xla.ActiveSheet;
// Now create the chart.
ChartObjects chartObjs = (ChartObjects)ws.ChartObjects(Type.Missing);
ChartObject chartObj = chartObjs.Add(100, 20, 300, 300);
Chart xlChart = chartObj.Chart;
Range rg = ws.get_Range("B2", "C17");
xlChart.SetSourceData(chartRange, XlRowCol.xlColumns);
thanks
The Control Chart or C-chart is a type of control chart that is used in the monitoring of count-type data which is usually the total number of conformities per unit. It is also sometimes used in monitoring the sum of events occurring in a given unit of time.
A p-chart is used to record the proportion of defective units in a sample. A c-chart is used to record the number of defects in a sample.
In statistical quality control, the c-chart is a type of control chart used to monitor "count"-type data, typically total number of nonconformities per unit. It is also occasionally used to monitor the total number of events occurring in a given unit of time.
I cleaned the code up a bit and added the generation of random data so this should run on its own.
Random random = new Random();
Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();
xla.Visible = true;
Workbook wb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet ws = (Worksheet)xla.ActiveSheet;
// Now create the chart.
ChartObjects chartObjs = (ChartObjects)ws.ChartObjects();
ChartObject chartObj = chartObjs.Add(150, 20, 300, 300);
Chart xlChart = chartObj.Chart;
// generate some random data
for (int row = 0; row < 16; row++)
{
ws.Cells[row + 2, 2] = row + 1;
ws.Cells[row + 2, 3] = random.Next(100);
}
Range xValues = ws.Range["B2", "B17"];
Range values = ws.Range["C2", "C17"];
SeriesCollection seriesCollection = xlChart.SeriesCollection();
Series series1 = seriesCollection.NewSeries();
series1.XValues = xValues;
series1.Values = values;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With