Crea grafici a candela (apertura-alto-basso-chiusura azioni) tramite C#
Creazione di grafici MS Excel nativi e ad alte prestazioni a livello di codice utilizzando le API .NET lato server.
Come creare grafici a candela (apertura-alto-basso-chiusura azioni) tramite C#
È facile per gli sviluppatori creare un grafico a candela eseguendo diverse applicazioni di reporting per l’elaborazione dei dati in poche righe di codice.
- Includi lo spazio dei nomi nel file della classe
- Creare Cartella di lavoro istanza di classe di file Excel di esempio .
- Aggiungere un Azioni Apri-Alto-Basso-Chiudi Grafico nel foglio di lavoro chiamando il file Grafici collezione Aggiungere metodo, incapsulato nel Foglio di lavoro oggetto.
- Accedi al nuovo Grafico oggetto dalla raccolta Charts passando il relativo indice.
- Imposta l’origine dati del grafico con Chart.SetChartDataRange metodo.
- Imposta i dati della categoria con CategoriaDati proprietà.
- Salva come Excel o ODS File di uscita .
Requisiti di sistema
Assicurati solo che il sistema abbia Microsoft Windows o un sistema operativo compatibile con .NET Framework, .NET Core, Windows Azure, Mono o piattaforme Xamarin, nonché un ambiente di sviluppo come Microsoft Visual Studio.
- Installa dalla riga di comando comenuget install Aspose.Cells
o tramite la console di gestione pacchetti di Visual Studio conInstall-Package Aspose.Cells
.
- In alternativa, ottieni il programma di installazione MSI offline o tutte le DLL in un file ZIP dadownloadIl seguente codice sorgente mostra come creare un grafico a candela (azioni Open-High-Low-Close) nel file MS Excel XLSX utilizzando C#.
// Create an instance of Workbook | |
Workbook workbook = new Workbook("Open-High-Low-Close.xlsx"); | |
// Access the first worksheet. | |
Worksheet worksheet = workbook.Worksheets[0]; | |
//Create High-Low-Close-Stock Chart | |
int pieIdx = worksheet.Charts.Add(ChartType.StockOpenHighLowClose, 5, 6, 20, 12); | |
// Retrieve the Chart object | |
Chart chart = worksheet.Charts[pieIdx]; | |
// Set the legend can be showed | |
chart.ShowLegend = true; | |
// Set the chart title name | |
chart.Title.Text = "OPen-High-Low-Close Stock"; | |
// Set the Legend at the bottom of the chart area | |
chart.Legend.Position = LegendPositionType.Bottom; | |
// Set data range | |
chart.SetChartDataRange("A1:E9", true); | |
// Set category data | |
chart.NSeries.CategoryData = "A2:A9"; | |
// Set the DownBars and UpBars with different color | |
chart.NSeries[0].DownBars.Area.ForegroundColor = Color.Green; | |
chart.NSeries[0].UpBars.Area.ForegroundColor = Color.Red; | |
// Fill the PlotArea area with nothing | |
chart.PlotArea.Area.FillFormat.FillType = FillType.None; | |
// Save the Excel file | |
workbook.Save("out.xlsx"); |