Need sample aspose program to plot chart in excel

Stacked_BarWithLine_Not_Visible.zip (12.9 KB)

Please refer the chart shared. It has stacked bar chart with line. On line marker shape is diamond and line is not visible.

@VaradS,

See the following sample code to accomplish your task. I have used data in your Excel spreadsheet for chart’s data source and generated another (similar) chart in the same worksheet for your reference. Please refer to the code segment and write/update your code accordingly for your needs.
e.g.,
Sample code:

Workbook workbook = new Workbook("d:\\files\\Stacked_BarWithLine_Not_Visible.xlsx");
Worksheet worksheet = workbook.getWorksheets().get(0);


//Add a chart to the worksheet
int chartIndex = worksheet.getCharts().add(ChartType.COLUMN_STACKED, 25, 1, 42, 10);
Chart chart = worksheet.getCharts().get(chartIndex);

//Add the stacked column series (primary axis)
chart.getNSeries().add("B2:D6", true);
chart.getNSeries().setCategoryData("A2:A6");

//set names of the series
for (int i = 0 ;i < chart.getNSeries().getCount(); i ++)
{
     Series series = chart.getNSeries().get(i);
     series.setName(workbook.getWorksheets().get(0).getCells().get(0,i+1).getValue().toString());
}

//Add the first line series (Line) and set it to secondary axis
int seriesIndex1 = chart.getNSeries().add("E2:E6", true);
Series lineSeries1 = chart.getNSeries().get(seriesIndex1);
lineSeries1.setType(ChartType.LINE);
lineSeries1.setPlotOnSecondAxis(true);  // Secondary axis
lineSeries1.setName(workbook.getWorksheets().get(0).getCells().get(0,4).getValue().toString());

//Add the second line series (Line with markers) and set it to secondary axis
int seriesIndex2 = chart.getNSeries().add("F2:F6", true);
Series lineSeries2 = chart.getNSeries().get(seriesIndex2);
lineSeries2.setType(ChartType.LINE);
lineSeries2.setPlotOnSecondAxis(true);  // Secondary axis
lineSeries2.setName(workbook.getWorksheets().get(0).getCells().get(0,5).getValue().toString());

//Format the line series with markers
Line line2 = lineSeries2.getBorder();
line2.setVisible(false);  // Make the line invisible
Marker marker = lineSeries2.getMarker();
marker.setMarkerStyle(ChartMarkerType.DIAMOND);  // Set marker shape to diamond
marker.setMarkerSize(8);  // Optional: Set marker size
marker.getBorder().setColor(com.aspose.cells.Color.getPurple());
marker.getArea().setForegroundColor(com.aspose.cells.Color.getPurple());

chart.getLegend().setPosition(LegendPositionType.BOTTOM);

//Save the workbook
workbook.save("d:\\files\\outComboChart1.xlsx");

Please find attached the output Excel file containing the new chart.
outComboChart1.zip (14.2 KB)

Hope, this helps a bit.

How can we select no line?
image.png (20.6 KB)

I can still see the blue line in the output shared by you.
image.png (56.4 KB)

@VaradS,

Thanks for the screenshots.

Please add a line (in bold) to the code segment.

//Add the first line series (Line) and set it to secondary axis
int seriesIndex1 = chart.getNSeries().add(“E2:E6”, true);
Series lineSeries1 = chart.getNSeries().get(seriesIndex1);
lineSeries1.setType(ChartType.LINE);
lineSeries1.setPlotOnSecondAxis(true); // Secondary axis
lineSeries1.setName(workbook.getWorksheets().get(0).getCells().get(0,4).getValue().toString());
//Hide the line by setting the Line property to null
lineSeries1.getBorder().setVisible(false);

Hope, this helps a bit.

@VaradS
Please refer to the following example code to set chart border to “No line” and hide blue line. Please check the attachment. outComboChart1_java.zip (14.9 KB)

Workbook workbook = new Workbook(filePath + "Stacked_BarWithLine_Not_Visible.xlsx");
Worksheet worksheet = workbook.getWorksheets().get(0);


//Add a chart to the worksheet
int chartIndex = worksheet.getCharts().add(ChartType.COLUMN_STACKED, 25, 1, 42, 10);
Chart chart = worksheet.getCharts().get(chartIndex);

//Add the stacked column series (primary axis)
chart.getNSeries().add("B2:D6", true);
chart.getNSeries().setCategoryData("A2:A6");

//set names of the series
for (int i = 0 ;i < chart.getNSeries().getCount(); i ++)
{
     Series series = chart.getNSeries().get(i);
     series.setName(workbook.getWorksheets().get(0).getCells().get(0,i+1).getValue().toString());
}

//Add the first line series (Line) and set it to secondary axis
int seriesIndex1 = chart.getNSeries().add("E2:E6", true);
Series lineSeries1 = chart.getNSeries().get(seriesIndex1);
lineSeries1.setType(ChartType.LINE);
lineSeries1.setPlotOnSecondAxis(true);  // Secondary axis
lineSeries1.setName(workbook.getWorksheets().get(0).getCells().get(0,4).getValue().toString());

//Add the second line series (Line with markers) and set it to secondary axis
int seriesIndex2 = chart.getNSeries().add("F2:F6", true);
Series lineSeries2 = chart.getNSeries().get(seriesIndex2);
lineSeries2.setType(ChartType.LINE);
lineSeries2.setPlotOnSecondAxis(true);  // Secondary axis
lineSeries2.setName(workbook.getWorksheets().get(0).getCells().get(0,5).getValue().toString());

//Format the line series with markers
Line line2 = lineSeries2.getBorder();
line2.setVisible(false);  // Make the line invisible
Marker marker = lineSeries2.getMarker();
marker.setMarkerStyle(ChartMarkerType.DIAMOND);  // Set marker shape to diamond
marker.setMarkerSize(8);  // Optional: Set marker size
marker.getBorder().setColor(com.aspose.cells.Color.getPurple());
marker.getArea().setForegroundColor(com.aspose.cells.Color.getPurple());

chart.getLegend().setPosition(LegendPositionType.BOTTOM);

//hide blue line
lineSeries1.getBorder().setVisible(false);
//set chart border to "No line"
chart.getChartArea().getBorder().setVisible(false);

//Save the workbook
workbook.save(filePath + "outComboChart1_java.xlsx");

Hope helps a bit.