Write a code snippet to plot similar chart in Excel

I need help to plot the similar chart in excel. Please help me with code example on it using Cells library.
HToCrBChart_out3.zip (12.1 KB)

@VaradS,

See the following sample code to accomplish your task. I have used your template Excel file (you provided) for data source and created similar (new) chart in same worksheet below your desired chart. Please refer to the sample code and write/update the code segment accordingly if you still want to set other formatting options of the chart for your needs.
e.g.,
Sample code:


        Workbook workbook = new Workbook("d:\\files\\HToCrBChart_out3.xlsx");

        Worksheet worksheet = workbook.getWorksheets().get(0);
        int i = worksheet.getCharts().add(ChartType.SCATTER_CONNECTED_BY_CURVES_WITHOUT_DATA_MARKER,37,3,65, 15);
        Chart chart= worksheet.getCharts().get(i);

        ChartFrame plotArea = chart.getPlotArea();
        plotArea.getArea().getFillFormat().setPattern(BackgroundType.NONE);

        plotArea.getArea().setBackgroundColor(com.aspose.cells.Color.getTransparent());
        plotArea.getArea().setForegroundColor(com.aspose.cells.Color.getTransparent());

        //Setting the chart area
        ChartArea chartArea = chart.getChartArea();

        //Removing the legend...etc.
        chart.setWallsAndGridlines2D(false);
        chart.setShowDataTable(false);
        chart.setShowLegend(false);

        //Set Properties of nseries
        int s1_idx = chart.getNSeries().add("=(Sheet1!$Q$10,Sheet1!$Q$13,Sheet1!$Q$16,Sheet1!$Q$19)", true);
        chart.getNSeries().get(s1_idx).setXValues("=(Sheet1!$O$10,Sheet1!$O$13,Sheet1!$O$16,Sheet1!$O$19)");

        int s2_idx = chart.getNSeries().add("=(Sheet1!$Q$11,Sheet1!$Q$14,Sheet1!$Q$17,Sheet1!$Q$20)", true);
        chart.getNSeries().get(s2_idx).setXValues("=(Sheet1!$O$11,Sheet1!$O$14,Sheet1!$O$17,Sheet1!$O$20)");

        int s3_idx = chart.getNSeries().add("=(Sheet1!$Q$12,Sheet1!$Q$15,Sheet1!$Q$18,Sheet1!$Q$21)", true);
        chart.getNSeries().get(s3_idx).setXValues("=(Sheet1!$O$12,Sheet1!$O$15,Sheet1!$O$18,Sheet1!$O$21)");

        //Set the attributes for the first series to dotted line
        Series aseries;
        aseries = chart.getNSeries().get(0);
        Line line1 = aseries.getBorder();
        line1.setDashType(MsoLineDashStyle.SOLID);
        line1.setCapType(LineCapType.ROUND);
        line1.setColor(com.aspose.cells.Color.getBlue());
        line1.setWeightPt(1.5);
        line1.setBeginType(MsoArrowheadStyle.ARROW);
        line1.setEndType(MsoArrowheadStyle.ARROW_DIAMOND);
        line1.setBeginArrowWidth(2);
        line1.setEndArrowWidth(2);
        line1.setVisible(true);

        //Set the second series attributes
        Series aseries1;
        aseries1 = chart.getNSeries().get(1);
        Line line2 = aseries1.getBorder();
        line2.setDashType(MsoLineDashStyle.SOLID);
        line2.setCapType(LineCapType.ROUND);
        line2.setColor(com.aspose.cells.Color.getBrown());
        line2.setBeginType(MsoArrowheadStyle.ARROW);
        line2.setEndType(MsoArrowheadStyle.ARROW_DIAMOND);
        line2.setBeginArrowWidth(2);
        line2.setEndArrowWidth(2);
        line2.setWeightPt(1.5);
        line2.setVisible(true);


        //Set the third series attributes
        Series aseries2;
        aseries2 = chart.getNSeries().get(2);
        Line line3 = aseries2.getBorder();
        line3.setDashType(MsoLineDashStyle.SOLID);
        line3.setCapType(LineCapType.ROUND);
        line3.setColor(com.aspose.cells.Color.getGray());
        line3.setWeightPt(1.5);
        line3.setBeginType(MsoArrowheadStyle.ARROW);
        line3.setEndType(MsoArrowheadStyle.ARROW_DIAMOND);
        line3.setBeginArrowWidth(2);
        line3.setEndArrowWidth(2);
        line3.setWeightPt(1.5);
        line3.setVisible(true);

        chart.getValueAxis().getMajorGridLines().setFormattingType(FormattingType.CUSTOM);
        chart.getValueAxis().getMajorGridLines().setColor(com.aspose.cells.Color.getLightGray());

        workbook.save("d:\\files\\out_chart1asdfasdfasdf191.xlsx");

Please find attached the output Excel file containing the new chart in the same worksheet for your reference.
out_chart1.zip (13.4 KB)

Hope, this helps a bit.

Hi @amjad.sahi ,
Thanks for your help. Could you let me know if Aspose internally maps the
line1.setBeginArrowWidth(2);
line1.setBeginArrowLength(2);
to specific pixel values?

@VaradS,

See the API pages and check the constant values for MsoArrowheadWidth and MsoArrowheadLength enums for your reference.

With the information available in the API page I could not see any pixel size information. But what we are trying to understand is If are selecting the wide size is there any internal logic by aspose to set specific pixel size?

@VaradS
The width and length of the arrow do not have specific size settings. By setting enumeration values for the width and length of the arrow, a fixed arrow size will be matched. These sizes perfectly match all the arrow types supported by Excel. Please refer to the attachment. result.png (80.5 KB)