Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Mon Sep 16, 2019 2:47 pm

Hi,

I have a chart with 2 different axis, primary and secondary.

I can format the primary axis on the left.

chart.PrimaryValueAxis.IsSourceLinked = False
chart.PrimaryValueAxis.NumberFormat = "0,000"

but how to format the second axis and I also what the position of the axis on the right side of may chart.
and also give the axis a title.

thank your for help.
GH

GHWels
 
Posts: 90
Joined: Sun Nov 23, 2014 7:22 pm

Tue Sep 17, 2019 3:58 am

Hi,

Thanks for your inquiry.
Please refer to the code below to set the format of the secondary axis and set the title of it.

Code: Select all
        'Get the chart
        Dim chart As Chart = sheet.Charts(0)

        'Get the series
        Dim cs1 As ChartSerie = chart.Series(1)

        'Set the value
        cs1.Values = sheet.Range("C2:C9")

        'Use the secondary axis
        cs1.UsePrimaryAxis = False

        'Set the format
        chart.SecondaryValueAxis.IsSourceLinked = False
        chart.SecondaryValueAxis.NumberFormat = "0,000"

        'Set the title
        chart.SecondaryValueAxis.Title = "Secondary Axis"


And the position of the secondary axis will be on the right side of your chart automatically. If the code couldn’t solve your issue, to help us better investigate it, please offer us your input Excel file and your desired result file.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Tue Sep 17, 2019 5:05 am

Hi Amber,

the secondary Data are still on the left side.
the secondary title on the right side.



Dim saveName As String = "C:\Temp\TZP.xlsx"
Dim wb As New Workbook()
wb = New Workbook()
wb.LoadFromFile(saveName, ExcelVersion.Version2016)
wb.Worksheets.Remove(1)

Dim GSheet As Worksheet = WB.CreateEmptySheet
GSheet.Name = "Grafik"
GSheet.GridLinesVisible = False
Dim Grafik As Chart = GSheet.Charts.Add()
Grafik.LeftColumn = 1
Grafik.TopRow = 1
Grafik.RightColumn = 25
Grafik.BottomRow = 60

Grafik.ChartTitle = "Data: " & Now().ToShortDateString
Grafik.ChartTitleArea.IsBold = True
Grafik.ChartTitleArea.Size = 12

Dim sheet As Worksheet = wb.Worksheets(0)
Grafik.DataRange = Sheet.Range("A1:C140")
Grafik.SeriesDataFromRange = False

Grafik.PrimaryValueAxis.Title = "Data"
Grafik.PrimaryValueAxis.IsSourceLinked = False
Grafik.PrimaryValueAxis.NumberFormat = "0,000"
Grafik.PrimaryCategoryAxis.Title = "KW"
Grafik.PrimaryCategoryAxis.TextRotationAngle = 60

Dim cs1 As Charts.ChartSerie = Grafik.Series(1)
cs1.SerieType = ExcelChartType.LineStacked
cs1.UsePrimaryAxis = False
cs1.DataFormat.ShowActiveValue = True

Grafik.SecondaryValueAxis.IsSourceLinked = False
Grafik.SecondaryValueAxis.NumberFormat = "0,000"
Grafik.SecondaryValueAxis.Title = "kum. Data"

Grafik.Legend.Position = LegendPositionType.Bottom
wb.SaveToFile(saveName, ExcelVersion.Version2016)

Spreadsheet1.LoadFromFile(saveName)

GH
Attachments
TZP.zip
(14.27 KiB) Downloaded 193 times

GHWels
 
Posts: 90
Joined: Sun Nov 23, 2014 7:22 pm

Tue Sep 17, 2019 11:11 am

Hi,

Thanks for your information.
After further investigation, sorry that the property of setting the position of the secondary axis is not public. Once the property is public, we will let you know.
Sorry for the inconvenience caused.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Tue Sep 17, 2019 12:00 pm

Hi Amber,

Thanks for yout help and feedback.
I hope for an implementation.

GH

GHWels
 
Posts: 90
Joined: Sun Nov 23, 2014 7:22 pm

Wed Sep 18, 2019 9:52 am

Hi,

Thanks for your patient waiting.
After further investigation, we found that although the property(SecondaryCategoryAxis.AxisPosition) of setting the position of the secondary axis is not public yet, if we set the "IsMaxCross" property of the secondary category axis as true, the position of the secondary axis could just be on the right side of the chart. Below is the code for your reference.
Code: Select all
        Grafik.SecondaryCategoryAxis.IsMaxCross = True


Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Wed Oct 30, 2019 9:53 am

Hi,

Greetings from E-iceblue.
Have you tried the code I offered you last time? Does it solve your issue?
Could you please give us some feedback at your convenience?

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Return to Spire.XLS