Hello,
I am trying to generate chart that include following types
-
Line Chart - NBP Supplier Volume
-
Column Stack - Base + Peak load volume
-
Area - NBP Event volume
Below is the code to generate the charts and also see the attachment
Generating to excel and gives correct output, please check the attachment ‘ExcelBasePeakLoad.png’
When we convert the chart to image, see the attachment “basePeakConvertTomage.jpg”, we have couple of issues
-
Line Chart is not clear – it shows zigzag line
-
Area chart – NBP Event volume is overlapping the Base+peak load volume
Please advise how we can avoid the zigzag in the line and overlapping of area chart
wsVolumeChartData.Charts.Clear();
int chartIndex = 0;
chartIndex =
wsVolumeChartData.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 18, 1, 45,
20);
Aspose.Cells.Charts.Chart chart =
wsVolumeChartData.Charts[chartIndex];
chart.ValueAxis.MajorGridLines.IsVisible = false;
chart.PlotArea.Area.ForegroundColor =
System.Drawing.Color.White;
chart.ChartArea.Border.IsVisible = false;
if (this.FlexStructure == EnumFlexStructureList.Baseload)
{
chart.NSeries.Add(string.Format("=VolumeChartData!$B$1:$B${0}",
numberOfMonths), true);
chart.NSeries.Add(string.Format("=VolumeChartData!$C$1:$C${0}",
numberOfMonths), true);
chart.NSeries.Add(string.Format("=VolumeChartData!$D$1:$D${0}",
numberOfMonths), true);
}
if (this.FlexStructure == EnumFlexStructureList.BaseloadPeakload)
{
chart.NSeries.Add(string.Format("=VolumeChartData!$B$1:$B${0}", numberOfMonths), true);
chart.NSeries.Add(string.Format("=VolumeChartData!$C$1:$C${0}", numberOfMonths), true);
chart.NSeries.Add(string.Format("=VolumeChartData!$D$1:$D${0}", numberOfMonths), true);
chart.NSeries.Add(string.Format("=VolumeChartData!$E$1:$E${0}", numberOfMonths), ue); }
chart.NSeries.CategoryData = string.Format("=VolumeChartData!$A$1:$A${0}", numberOfMonths);
chart.CategoryAxis.TickLabels.Font.Name = "Arial";
chart.CategoryAxis.TickLabels.Font.Size = 8;
chart.CategoryAxis.TickLabels.RotationAngle = 90;
chart.CategoryAxis.TickLabels.Font.IsBold = true;
chart.NSeries.SecondCatergoryData = string.Format("=VolumeChartData!$A$1:$A${0}",
umberOfMonths);
chart.SecondValueAxis.MinValue = 0;
if (this.FlexStructure == EnumFlexStructureList.Baseload)
{
chart.NSeries[0].Line.IsVisible = true;
chart.NSeries[0].Name = “NBP Event Volume (MWh)”;
chart.NSeries[0].Type = Aspose.Cells.Charts.ChartType.Area;
chart.NSeries[0].Area.ForegroundColor = Color.FromArgb(217, 217, 217);
chart.NSeries[0].Border.IsVisible = false;
chart.NSeries[0].Shadow = true;
}
if (this.FlexStructure == EnumFlexStructureList.Baseload)
{
if (this.FlexStructure == EnumFlexStructureList.Shape)
{
chart.NSeries[1].Name = “NBP Volume (MWh)”;
}
else
{
chart.NSeries[1].Name = “Baseload Volume (MWh)”;
}
chart.NSeries[1].PlotOnSecondAxis = true;
chart.NSeries[1].Area.ForegroundColor = Color.FromArgb(0, 133, 208);
chart.NSeries[1].Border.IsVisible = false;
//chart.NSeries[1].DataLabels.Separator = DataLablesSeparatorType.NewLine;
//chart.NSeries[1].Overlap = 100;
}
if (this.FlexStructure == EnumFlexStructureList.Baseload)
{
Series series = chart.NSeries[2];
series.Name = “NBP Supplier Volume (MWh)”;
series.Type = ChartType.Line;
chart.NSeries[2].Area.Formatting = Aspose.Cells.Charts.FormattingType.Automatic;
chart.NSeries[2].Line.Color = System.Drawing.Color.FromArgb(64, 64, 64);
chart.NSeries[2].Line.Style = Aspose.Cells.Drawing.LineType.Solid;
chart.NSeries[2].Line.WeightPt = 2.0;
}
if
(this.FlexStructure == EnumFlexStructureList.BaseloadPeakload)
{
Series Columnseries = chart.NSeries[0];
Columnseries.Type = Aspose.Cells.Charts.ChartType.Area;
chart.NSeries[0].Line.IsVisible = true;
chart.NSeries[0].Name = “NBP Event Volume (MWh)”;
chart.NSeries[0].Area.ForegroundColor = Color.FromArgb(217, 217, 217);
chart.NSeries[0].Border.IsVisible = false;
chart.NSeries[0].Shadow = true;
Series Stackseries = chart.NSeries[1];
Stackseries.Type = ChartType.ColumnStacked;
chart.NSeries[1].Area.ForegroundColor = Color.FromArgb(0, 133, 208);
chart.NSeries[1].Name = “Baseload Volume (MWh)”;
chart.NSeries[2].Area.ForegroundColor = Color.FromArgb(31, 73, 125);
chart.NSeries[2].Name = “Peakload Volume (MWh)”;
Series seriesline = chart.NSeries[3];
seriesline.Name = “NBP Supplier Volume (MWh)”;
seriesline.Type = ChartType.Line;
chart.NSeries[3].Area.Formatting = Aspose.Cells.Charts.FormattingType.Automatic;
chart.NSeries[3].Line.Color = System.Drawing.Color.FromArgb(64, 64, 64);
chart.NSeries[3].Line.Style = Aspose.Cells.Drawing.LineType.Solid;
chart.NSeries[3].Line.WeightPt = 2.0;
}
string ImageRefID =string.empty;
ImageRefID = System.Guid.NewGuid().ToString();
Session[“imageRefID”] = ImageRefID;
chart.ToImage(TemplatePath + “\Images\VolumeChart” + ImageRefID + “.jpeg”);
System.Web.UI.WebControls.Image VolumeChartImg = new System.Web.UI.WebControls.Image();
VolumeChartImg.ID = “VolumeChartImg”;
VolumeChartImg.ImageUrl = “~/Templates/Images/VolumeChart” + ImageRefID + “.jpeg”;
VolumeChartImg.BorderWidth = 0;
pnl_Volumechart.BorderWidth = 0;
pnl_Volumechart.Controls.Add(VolumeChartImg);
Thanks
Parvati
I am trying to generate chart that include following types
-
Line Chart - NBP Supplier Volume
-
Column Stack - Base + Peak load volume
-
Area - NBP Event volume
Below is the code to generate the charts and also see the attachment
Generating to excel and gives correct output, please check the attachment ‘ExcelBasePeakLoad.png’
When we convert the chart to image, see the attachment “basePeakConvertTomage.jpg”, we have couple of issues
-
Line Chart is not clear – it shows zigzag line
-
Area chart – NBP Event volume is overlapping the Base+peak load volume
Please advise how we can avoid the zigzag in the line and overlapping of area chart
wsVolumeChartData.Charts.Clear();
int chartIndex = 0;
chartIndex = wsVolumeChartData.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 18, 1, 45, 20);
Aspose.Cells.Charts.Chart chart = wsVolumeChartData.Charts[chartIndex];
chart.ValueAxis.MajorGridLines.IsVisible = false;
chart.PlotArea.Area.ForegroundColor = System.Drawing.Color.White;
chart.ChartArea.Border.IsVisible = false;
if (this.FlexStructure == EnumFlexStructureList.Baseload)
{
chart.NSeries.Add(string.Format("=VolumeChartData!$B$1:$B${0}", numberOfMonths), true);
chart.NSeries.Add(string.Format("=VolumeChartData!$C$1:$C${0}", numberOfMonths), true);
chart.NSeries.Add(string.Format("=VolumeChartData!$D$1:$D${0}", numberOfMonths), true);
}
if (this.FlexStructure == EnumFlexStructureList.BaseloadPeakload)
{
chart.NSeries.Add(string.Format("=VolumeChartData!$B$1:$B${0}", numberOfMonths), true);
chart.NSeries.Add(string.Format("=VolumeChartData!$C$1:$C${0}", numberOfMonths), true);
chart.NSeries.Add(string.Format("=VolumeChartData!$D$1:$D${0}", numberOfMonths), true);
chart.NSeries.Add(string.Format("=VolumeChartData!$E$1:$E${0}", numberOfMonths), true); }
chart.NSeries.CategoryData = string.Format("=VolumeChartData!$A$1:$A${0}", numberOfMonths);
chart.CategoryAxis.TickLabels.Font.Name = "Arial";
chart.CategoryAxis.TickLabels.Font.Size = 8;
chart.CategoryAxis.TickLabels.RotationAngle = 90;
chart.CategoryAxis.TickLabels.Font.IsBold = true;
chart.NSeries.SecondCatergoryData = string.Format("=VolumeChartData!$A$1:$A${0}", numberOfMonths);
chart.SecondValueAxis.MinValue = 0;
if (this.FlexStructure == EnumFlexStructureList.Baseload)
{
chart.NSeries[0].Line.IsVisible = true;
chart.NSeries[0].Name = "NBP Event Volume (MWh)";
chart.NSeries[0].Type = Aspose.Cells.Charts.ChartType.Area;
chart.NSeries[0].Area.ForegroundColor = Color.FromArgb(217, 217, 217);
chart.NSeries[0].Border.IsVisible = false;
chart.NSeries[0].Shadow = true;
}
if (this.FlexStructure == EnumFlexStructureList.Baseload)
{
if (this.FlexStructure == EnumFlexStructureList.Shape)
{
chart.NSeries[1].Name = "NBP Volume (MWh)";
}
else
{
chart.NSeries[1].Name = "Baseload Volume (MWh)";
}
chart.NSeries[1].PlotOnSecondAxis = true;
chart.NSeries[1].Area.ForegroundColor = Color.FromArgb(0, 133, 208);
chart.NSeries[1].Border.IsVisible = false;
//chart.NSeries[1].DataLabels.Separator = DataLablesSeparatorType.NewLine;
//chart.NSeries[1].Overlap = 100;
}
if (this.FlexStructure == EnumFlexStructureList.Baseload)
{
Series series = chart.NSeries[2];
series.Name = "NBP Supplier Volume (MWh)";
series.Type = ChartType.Line;
chart.NSeries[2].Area.Formatting = Aspose.Cells.Charts.FormattingType.Automatic;
chart.NSeries[2].Line.Color = System.Drawing.Color.FromArgb(64, 64, 64);
chart.NSeries[2].Line.Style = Aspose.Cells.Drawing.LineType.Solid;
chart.NSeries[2].Line.WeightPt = 2.0;
}
if (this.FlexStructure == EnumFlexStructureList.BaseloadPeakload)
{
Series Columnseries = chart.NSeries[0];
Columnseries.Type = Aspose.Cells.Charts.ChartType.Area;
chart.NSeries[0].Line.IsVisible = true;
chart.NSeries[0].Name = "NBP Event Volume (MWh)";
chart.NSeries[0].Area.ForegroundColor = Color.FromArgb(217, 217, 217);
chart.NSeries[0].Border.IsVisible = false;
chart.NSeries[0].Shadow = true;
Series Stackseries = chart.NSeries[1];
Stackseries.Type = ChartType.ColumnStacked;
chart.NSeries[1].Area.ForegroundColor = Color.FromArgb(0, 133, 208);
chart.NSeries[1].Name = "Baseload Volume (MWh)";
chart.NSeries[2].Area.ForegroundColor = Color.FromArgb(31, 73, 125);
chart.NSeries[2].Name = "Peakload Volume (MWh)";
Series seriesline = chart.NSeries[3];
seriesline.Name = "NBP Supplier Volume (MWh)";
seriesline.Type = ChartType.Line;
chart.NSeries[3].Area.Formatting = Aspose.Cells.Charts.FormattingType.Automatic;
chart.NSeries[3].Line.Color = System.Drawing.Color.FromArgb(64, 64, 64);
chart.NSeries[3].Line.Style = Aspose.Cells.Drawing.LineType.Solid;
chart.NSeries[3].Line.WeightPt = 2.0;
}
string ImageRefID =string.empty;
ImageRefID = System.Guid.NewGuid().ToString();
Session["imageRefID"] = ImageRefID;
chart.ToImage(TemplatePath + "\\Images\\VolumeChart" + ImageRefID + ".jpeg");
System.Web.UI.WebControls.Image VolumeChartImg = new System.Web.UI.WebControls.Image();
VolumeChartImg.ID = "VolumeChartImg";
VolumeChartImg.ImageUrl = "~/Templates/Images/VolumeChart" + ImageRefID + ".jpeg";
VolumeChartImg.BorderWidth = 0;
pnl_Volumechart.BorderWidth = 0;
pnl_Volumechart.Controls.Add(VolumeChartImg);