Chart secondaryVerticalAxis and VerticalAxis coincide when saving (Java)

this is 18.9
18.9.jpg (43.9 KB)
this is 19.6
19.6.jpg (42.7 KB)

@ximoon,

Can you please share source file along with generated result and complete working sample code so that we may further investigate to help you out. Also please share desired output as well.

code like this

public class CreatingNormalCharts {

public static void main(String[] args) {
//ExStart:CreatingNormalCharts

// The path to the documents directory.
String dataDir = Utils.getDataDir(CreatingNormalCharts.class);

// Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation();

// Access first slide
ISlide sld = pres.getSlides().get_Item(0);

// Add chart with default data
IChart chart = sld.getShapes().addChart(ChartType.ClusteredColumn, 0, 0, 500, 500);

// Setting chart Title
// chart.ChartTitle.TextFrameForOverriding.Text = “Sample Title”;
chart.getChartTitle().addTextFrameForOverriding(“Sample Title”);
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText(NullableBool.True);
chart.getChartTitle().setHeight(20);
chart.hasTitle();

// Set first series to Show Values
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true);

// Setting the index of chart data sheet
int defaultWorksheetIndex = 0;

// Getting the chart data WorkSheet
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();

// Delete default generated series and categories
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
int s = chart.getChartData().getSeries().size();
s = chart.getChartData().getCategories().size();

// Adding new series
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 1, “Series 1”),chart.getType());
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 2, “Series 2”),chart.getType());

// Adding new categories
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 1, 0, “Caetegoty 1”));
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 2, 0, “Caetegoty 2”));
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 3, 0, “Caetegoty 3”));

// Take first chart series
IChartSeries series = chart.getChartData().getSeries().get_Item(0);

// Now populating series data

series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30));

// Setting fill color for series
series.getFormat().getFill().setFillType(FillType.Solid);
series.getFormat().getFill().getSolidFillColor().setColor(Color.RED);

// Take second chart series
series = chart.getChartData().getSeries().get_Item(1);
series.setPlotOnSecondAxis(true);

// Now populating series data
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 2, 30));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 2, 10));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 2, 60));

// Setting fill color for series
series.getFormat().getFill().setFillType(FillType.Solid);
series.getFormat().getFill().getSolidFillColor().setColor(Color.GREEN);

// create custom labels for each of categories for new series
// first label will be show Category name
IDataLabel lbl = series.getDataPoints().get_Item(0).getLabel();
lbl.getDataLabelFormat().setShowCategoryName(true);

lbl = series.getDataPoints().get_Item(1).getLabel();
lbl.getDataLabelFormat().setShowSeriesName(true);

// Show value for third label
lbl = series.getDataPoints().get_Item(2).getLabel();
lbl.getDataLabelFormat().setShowValue(true);
lbl.getDataLabelFormat().setShowSeriesName(true);
lbl.getDataLabelFormat().setSeparator("/");

// Save presentation with chart
pres.save(dataDir + “AsposeChart.pptx”, SaveFormat.Pptx);
//ExEnd:CreatingNormalCharts

}

}

@ximoon,

I have worked with sample code and generated output that i have shared with you for your kind reference. Can you please share your generated file along with desired output so that we may further investigate to help you out.AsposeChart111.zip (33.8 KB)

I use the same code but genearted file is different.
AsposeCompare.zip (70.2 KB)

I mean why secondaryVerticalAxis and VerticalAxis coincide?I don’t know what caused it.

And how can I set ClusteredColumn Chart secondaryVerticalAxis Position

@ximoon,

I have observed your comments. I have shared sample code with you. This will help you to achieve your requirements.

chart.getAxes().getSecondaryVerticalAxis().setTickLabelPosition(TickLabelPositionType.High)

I do this,but the secondaryVerticalAxis and VerticalAxis coincideAsposeChart19.6.zip (35.1 KB)

@ximoon,

I have observed the issue of primary and secondary vertical axis being plotted along side. An issue with ID SLIDESJAVA-37702 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

The issues you have found earlier (filed as SLIDESJAVA-37702) have been fixed in this update.

I tried, but the problem hasn’t been solved yet.

@ximoon

Can you please provide the source file and generated output that you have obtained after using latest version on your end for reference.

This is code and source file.The version I used was 19.7.simple_chart.zip (36.5 KB)

@ximoon,

Can you please try using following sample code on your end.

// Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation();

// Access first slide
ISlide sld = pres.getSlides().get_Item(0);

// Add chart with default data
IChart chart = sld.getShapes().addChart(ChartType.ClusteredColumn, 0, 0, 500, 500);

// Setting chart Title
chart.getChartTitle().addTextFrameForOverriding("Sample Title");
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText(NullableBool.True);
chart.getChartTitle().setHeight(20);
chart.hasTitle();

// Set first series to Show Values
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true);

// Setting the index of chart data sheet
int defaultWorksheetIndex = 0;

// Getting the chart data WorkSheet
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();

// Delete default generated series and categories
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
int s = chart.getChartData().getSeries().size();
s = chart.getChartData().getCategories().size();

// Adding new series
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 1, "Series 1"),chart.getType());
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 2, "Series 2"),chart.getType());

// Adding new categories
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1"));
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2"));
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3"));

// Take first chart series
IChartSeries series = chart.getChartData().getSeries().get_Item(0);

// Now populating series data
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30));

// Setting fill color for series
series.getFormat().getFill().setFillType(FillType.Solid);
series.getFormat().getFill().getSolidFillColor().setColor(Color.RED);

// Take second chart series
series = chart.getChartData().getSeries().get_Item(1);
series.setPlotOnSecondAxis(true);

// Now populating series data
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 2, 30));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 2, 10));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 2, 60));

// Setting fill color for series
series.getFormat().getFill().setFillType(FillType.Solid);
series.getFormat().getFill().getSolidFillColor().setColor(Color.GREEN);

// create custom labels for each of categories for new series
// first label will be show Category name
IDataLabel lbl = series.getDataPoints().get_Item(0).getLabel();
lbl.getDataLabelFormat().setShowCategoryName(true);

lbl = series.getDataPoints().get_Item(1).getLabel();
lbl.getDataLabelFormat().setShowSeriesName(true);

// Show value for third label
lbl = series.getDataPoints().get_Item(2).getLabel();
lbl.getDataLabelFormat().setShowValue(true);
lbl.getDataLabelFormat().setShowSeriesName(true);
lbl.getDataLabelFormat().setSeparator("/");

// Move Primary and Secondary vertical axis
chart.getAxes().getSecondaryHorizontalAxis().setTickLabelPosition(TickLabelPositionType.High);
chart.getAxes().getSecondaryVerticalAxis().setTickLabelPosition(TickLabelPositionType.High);

// Save presentation with chart
pres.save("AsposeChart.pptx", SaveFormat.Pptx);

I generated the file with the code you gave me, and removed the grid lines from the file.But problems remain.simpleChart.zip (36.0 KB)

@ximoon,

I have opened the attached presentation on my end and have observed vertical axis on opposite sides of each other. Can you please share the snapshot of issue on your end along with complete PowerPoint version.

This is my PowerPoint version 2019-08-02_092503.jpg (4.0 KB)
This is my file.2019-08-02_092348.jpg (64.8 KB)

@ximoon,

I have observed your snapshot. The earlier issue was that both primary and secondary vertical axis were overlapped and this issue has been solved after I shared the sample code with you. Can you please share the elaboration what further issue you are having as in your snapshot too, I can see primary and vertical axis apart.

I mean vertical and secondary vertical, not vertical and horizontal axis.