Hi,
Hi Tamas,
Thanks for your posting and considering Aspose.Cells.
If I am not mistaken, I think, you want to change the Maximum Value of the Value Axis as shown in this screenshot.
You can change it using the Chart.ValueAxis.MaxValue property.
Please see the following code, I have attached the source and output files for your reference.
C#
//Create workbook object from source file
Workbook workbook = new Workbook(“source.xlsx”);
//Access the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
//Access the first chart in this worksheet
Chart chart = worksheet.Charts[0];
//Change the MaxValue of the Value Axis
chart.ValueAxis.MaxValue = 60;
//Save the workbook
workbook.Save(“output.xlsx”);
Screenshot:
Hi Shakeel,
Hi Tamas,
Thanks for your posting and using Aspose.Cells.
Please also provide us your expected output xlsx file as you have shown in the screenshot (desired pivot chart.jpg). You can create it manually using MS-Excel and post it here. It will help us look into your issue and we will be able to suggest you a sample code or workaround.
Hi,
Hi Tamas,
Thanks for your sample file and using Aspose.Cells.
I have looked into your issue and I found if you do the following changes as highlighted in red, then your pivot chart is created as expected.
I have attached the output xlsx file generated by this code.
VB.NET
'Instantiating a Workbook object
Dim wb As Workbook = New Workbook(“F:\Shak-Data-RW\Downloads\test\Aspose06\Aspose06\bin\Debug\charttest.xlsx”)
Dim ps As Aspose.Cells.Worksheet = wb.Worksheets.Add(“PivotTable”)
'Getting the pivottables collection in the sheet
Dim pivotTables As Aspose.Cells.Pivot.PivotTableCollection = ps.PivotTables
'Adding a PivotTable to the worksheet
Dim index As Integer = pivotTables.Add("=Data!A1:D8", “A1”, “PivotTable1”)
'Accessing the instance of the newly added PivotTable
Dim pivotTable As Aspose.Cells.Pivot.PivotTable = pivotTables(index)
'Defining Rows for pivot table
Dim rowindex As Integer = pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Row, “Creation”)
Dim rf As PivotField = pivotTable.RowFields(rowindex)
'Defining Data column for pivot table
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Data, “MY ID”)
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Data, “Rate”)
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Data, “Hours”)
pivotTable.DataFields(“Hours”).Function = ConsolidationFunction.Sum
Dim datafield As PivotField = pivottable.Rowfields(“Data”)
If datafield isnot Nothing
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Column, datafield)
End If
pivotTable.CalculateRange()
Dim oChartXL As Aspose.Cells.Charts.Chart
Dim chartsheet As Aspose.Cells.Worksheet = wb.Worksheets.Insert(ps.Index + 1, SheetType.Worksheet, “Testchart”)
Dim chartindex As Integer = chartsheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 0, 5, 28, 16)
oChartXL = chartsheet.Charts(chartindex)
'Setting the pivot chart data source
oChartXL.PivotSource = ps.name & “!” & pivotTable.name
oChartXL.HidePivotFieldButtons = False
Dim Area As String = Aspose.Cells.CellsHelper.CellIndexToName(pivottable.TableRange1.StartRow,pivottable.TableRange1.StartColumn) & “:” & Aspose.Cells.CellsHelper.CellIndexToName(pivottable.TableRange1.EndRow,pivottable.TableRange1.EndColumn)
oChartXL.NSeries.Add(“B2:D4”, True)
oChartXL.NSeries(0).Type = Charts.ChartType.LineWithDataMarkers
oChartXL.NSeries(1).Type = Charts.ChartType.LineWithDataMarkers
'oChartXL.NSeries(2).Type = Charts.ChartType.LineWithDataMarkers
'oChartXL.NSeries(3).Type = Charts.ChartType.ColumnStacked
wb.Save(“F:\Shak-Data-RW\Downloads\test\Aspose06\Aspose06\bin\Debug\outcharttest_new.xlsx”)
Hi Shakeel,
Hi Tamas,
Thanks for your feedback and using Aspose.Cells.
It is good to know that your issue is resolved with the above code change. Let us know if you encounter any other issue, we will be glad to look into it and help you further.
Hi Shakeel,