Change the look of a chart, using color or the new Chart Styles.
Developers can costomize and modify all the colors in PDF chart, contains series fill color, plot area border color and background color, legend color.
The first sample shows how to change a column chart color in different series using C# language.
Chart chart = new Chart(ChartType.Column2D); Series series = chart.SeriesCollection.AddSeries(); series.Name = "Series 1"; series.Add(new double[] { 1, 5, 3, 20, 11 }); // Set color for 1st series, all the column shapes // in the 1st series will show the same color as 'Gold' series.FillFormat.Color = XColors.Gold; series = chart.SeriesCollection.AddSeries(); series.Name = "Series 2"; series.Add(new double[] { 22, 4, 12, 8, 12 }); // set color for 2nd series, all the column shapes // in the 2nd series will displa the same color as 'Cyan' series.FillFormat.Color = XColors.Cyan; // Set plot border color chart.PlotArea.LineFormat.Color = XColors.Black; chart.PlotArea.LineFormat.Visible = true; // Set plot background color chart.PlotArea.FillFormat.Color = XColors.White; // Set legend chart.Legend.Docking = DockingType.Right; chart.Legend.LineFormat.Color = XColors.Red;
The second example shows how to set pie chart color in C#.NET code. PDF pie chart is a little different from other chart type, because the pie chart usually contains only single series of data, which other type of chart will has multiple series. So in pie chart, users always want to modify the color for each data point.
Chart chart = new Chart(ChartType.Pie2D); // Add series data Series series = chart.SeriesCollection.AddSeries(); series.Add(new double[] { 5, 6, 3 }); // Add series legend XSeries xseries = chart.XValues.AddXSeries(); xseries.Add("Series 1", "Series 2", "Series 3"); chart.Legend.Docking = DockingType.Right; // Set fill color for series 1 series.Elements[0].FillFormat.Color = XColors.Red; // Set fill color for series 2 series.Elements[1].FillFormat.Color = XColors.Blue; // Set fill color for series 3 series.Elements[2].FillFormat.Color = XColors.Yellow;
The third demo shows how to costomize the color for chart frame in C# code. PDF chart maker control use chart frame to add the chart graphics to the PDF page.
ChartFrame chartFrame = new ChartFrame(); chartFrame.Location = new XPoint(30, 30); chartFrame.Size = new XSize(500, 600); // Set background color for frame chartFrame.BackgroudFormat = XBrushes.White; // Set border color for frame chartFrame.BorderFormat = XPens.Black; // the chart object can be created using the above samples chartFrame.Add(chart);
More Excel tutorial
- Generate linear Code128 to PDF in Visual C#
- How to use PDF Barcode Toolkit to add 2D QR barcode on PDF page
- Drawing Clustered Bar diagram to PDF page using C# and XsPDF DLL
- Making Bar graphing to PDF page using .NET and XsPDF SDK
- Page removing from PDF in C# is quite easy and quick using XsPDF source code for .NET