Основная и вторичная оси
Contents
[
Hide
]
Возможные сценарии использования
Когда числа в диаграмме значительно различаются в разных рядах данных, или когда у вас есть смешанные типы данных (цена и объем), отображайте один или несколько рядов данных на вторичной вертикальной (значений) оси. Масштаб вторичной вертикальной оси показывает значения соответствующих рядов данных. Вторичная ось работает хорошо в диаграмме, которая показывает комбинацию гистограмм и линейных диаграмм.
Работа с первичной и вторичной осями, как в Microsoft Excel
Пожалуйста, посмотрите примерный код, который создает новый файл Excel и помещает значения диаграммы в первый лист. Затем мы добавляем диаграмму и отображаем вторую ось.
Образец кода
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create an instance of Workbook | |
Workbook workbook = new Workbook(); | |
// Access the first worksheet. | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Put the sample values used in a chart | |
worksheet.Cells["A1"].PutValue("Region"); | |
worksheet.Cells["A2"].PutValue("Peking"); | |
worksheet.Cells["A3"].PutValue("New York"); | |
worksheet.Cells["A4"].PutValue("Paris"); | |
worksheet.Cells["B1"].PutValue("Sales Volume"); | |
worksheet.Cells["C1"].PutValue("Growth Rate"); | |
worksheet.Cells["B2"].PutValue(100); | |
worksheet.Cells["B3"].PutValue(80); | |
worksheet.Cells["B4"].PutValue(140); | |
worksheet.Cells["C2"].PutValue(0.7); | |
worksheet.Cells["C3"].PutValue(0.8); | |
worksheet.Cells["C4"].PutValue(1.0); | |
// Create a Scatter chart | |
int pieIdx = worksheet.Charts.Add(ChartType.Scatter, 6, 6, 15, 11); | |
// Retrieve the Chart object | |
Chart chart = worksheet.Charts[pieIdx]; | |
// Add Series | |
chart.NSeries.Add("B2:C4", true); | |
// Set the category data | |
chart.NSeries.CategoryData = "=Sheet1!$A$2:$A$4"; | |
// Set the Second-Axis | |
chart.NSeries[1].PlotOnSecondAxis = true; | |
// Show the Second-Axis | |
chart.SecondValueAxis.IsVisible = true; | |
// Set the second series ChartType to line | |
chart.NSeries[1].Type = Aspose.Cells.Charts.ChartType.Line; | |
// Set the series name | |
chart.NSeries[0].Name = "Sales Volume"; | |
chart.NSeries[1].Name = "Growth Rate"; | |
// Set the Legend at the bottom of the chart area | |
chart.Legend.Position = LegendPositionType.Bottom; | |
// Fill the PlotArea area with nothing | |
chart.PlotArea.Area.FillFormat.FillType = FillType.None; | |
// Save the file | |
workbook.Save("PrimaryandSecondaryAxis.xlsx"); |