I really need help, please.
I look at the chart, and both series have the right values but don't display them, but they only display the first and last values.
I managed to get the data for the columns to work, but then the x-axis did not work. When the x-axis works, I get the first and last data columns.
I use Dispose(true) in the routine that opens everything. I tried to use
ExcelHelper excelHelper = new ExcelHelper(path); but I can't find it in the Project Reference at the assembly list and the Com list
private void UpdateChartSeries()
{
Excel.Worksheet chartWorksheet = (Excel.Worksheet)frmFoodPantry.theWorkbook.Worksheets.get_Item("Totals");//Select the sheet the chart is on
//diaable the alearts
frmFoodPantry.objApp.DisplayAlerts = false;
Excel.Sheets sheets = frmFoodPantry.theWorkbook.Worksheets;
Excel.Worksheet totalWorksheet = (Excel.Worksheet)sheets.get_Item("Totals");
totalWorksheet.Activate();
//Unprotect the Totals sheet
totalWorksheet.Unprotect();
//Select the chart
Object chTotals = totalWorksheet.ChartObjects("ChartTotals");
// Access Bar chart
Excel.Chart chart = totalWorksheet.ChartObjects("ChartTotals").Chart;
////Excel.Chart chart = chTotals as Excel.Chart;
//chart.PlotArea.Select();
Excel.ChartObjects chartObj = (Excel.ChartObjects)chartWorksheet.ChartObjects();
Excel.Chart xlChart = chartWorksheet.ChartObjects("ChartTotals").chart;
Excel.SeriesCollection oSeriesCollection = (Excel.SeriesCollection)chart.SeriesCollection(misValue);
Excel.SeriesCollection serColl = chart.SeriesCollection();
serColl.Item(1).Delete();
serColl.Item(1).Delete();
Excel.Series HouseHolds = oSeriesCollection.NewSeries();
Excel.Series People = oSeriesCollection.NewSeries();
Excel.Range series1_range = chartWorksheet.get_Range("C3", "C" + emptyRow.ToString());
Excel.Range series2_range = chartWorksheet.get_Range("D3", "D" + emptyRow.ToString());
HouseHolds.Values = series1_range;
People.Values = series2_range;
// X-Axis
String xAxis = "B3" + "," + "B" + emptyRow.ToString();
Excel.Series xAxisSeries = (Excel.Series)xlChart.SeriesCollection(1);
xAxisSeries.XValues = "";
xAxisSeries.XValues = chartWorksheet.get_Range(xAxis);
////series1.Name = "HouseHolds";
////series2.Name = "People";
////xlChart.SeriesCollection("HouseHolds").Format.Line.ForeColor.RGB = (int)Excel.XlRgbColor.rgbRed;
////xlChart.SeriesCollection("People").Format.Line.ForeColor.RGB = (int)Excel.XlRgbColor.rgbBlue;
editsMade = true;
}
What I have tried:
////Excel.Range chartRange;
////Excel.Worksheet xlWorkSheet = (Excel.Worksheet)frmFoodPantry.theWorkbook.Worksheets.get_Item(1);
////Excel.ChartObjects xlCharts = (Excel.ChartObjects)xlWorkSheet.ChartObjects(Type.Missing);
////Excel.ChartObject myChart = (Excel.ChartObject)chartObj.Add(10, 80, 300, 250);
////Excel.Chart chartPage = myChart.Chart;
////Excel.Range chartRange1 = chartWorksheet.get_Range(("C3", "C" + emptyRow.ToString()), ("D3", "D" + emptyRow.ToString())); // ;
////xlChart.SetSourceData(chartRange, misValue);
////chartPage.Name = "HouseHolds";
////Charting sreies
////Charting.SeriesCollection Series = chartRange;
////Excel.Range chartRange;
////Excel.Worksheet xlWorkSheet = (Excel.Worksheet)frmFoodPantry.theWorkbook.Worksheets.get_Item(1);
////Excel.ChartObjects xlCharts = (Excel.ChartObjects)xlWorkSheet.ChartObjects(Type.Missing);
////Excel.ChartObject myChart = (Excel.ChartObject)chartObj.Add(10, 80, 300, 250);
////Excel.Chart chartPage = myChart.Chart;
////Excel.Range chartRange2 = chartWorksheet.get_Range("D3", "D" + emptyRow.ToString());
////xlChart.SetSourceData(chartRange, misValue);
// Series 1 values
////totalWorksheet = (Excel.Worksheet)frmFoodPantry.theWorkbook.Worksheets.get_Item(1);
////Excel.Range chartRange = totalWorksheet.get_Range("C3", "C" + emptyRow.ToString());
//Set series 1 to be equal to the number of familes
////xlChart.SeriesCollection("HouseHolds").Values = "=Totals!$C$3:$C" + emptyRow.ToString();
// Series 1
////string houseHolds = @"=Totals!$C$3:$C" + emptyRow.ToString();
////Excel.Series HouseHolds = (Excel.Series)xlChart.SeriesCollection("HouseHolds");
////HouseHolds.Values = chartWorksheet.get_Range(houseHolds);
////// Set the color for the bar
////xlChart.SeriesCollection("HouseHolds").Format.Line.ForeColor.RGB = (int)Excel.XlRgbColor.rgbRed;
////// Series 2
////string strPeople = @"=Totals!$D$3:$D" + emptyRow.ToString();
////Excel.Series People = (Excel.Series)xlChart.SeriesCollection("People");
////People.Values = chartWorksheet.get_Range(strPeople);
////// Set the color for the bar
////xlChart.SeriesCollection("People").Format.Line.ForeColor.RGB = (int)Excel.XlRgbColor.rgbBlue;
// X-Axis
////String xAxis = "B3" + "," + "B" + emptyRow.ToString();
////Excel.Series xAxisSeries = (Excel.Series)xlChart.SeriesCollection(1);
////xAxisSeries.XValues = chartWorksheet.get_Range(xAxis);
////String houseHolds = "C3" + "C" + emptyRow.ToString();
////SeriesCollection.Add = (houseHolds);
////String people = "D3" + "D" + emptyRow.ToString();
////Series.ReferenceEquals() = people;