HI,
I have two questios:
1. I hace a Line Chart but my horizontal Axes no adjust to data. Id like my axes from values 0 to 6. Attach image "Sin título1.png".
2. It is possible that the legend xx is collocated on the Y axis, that is, on the 140. Similar to sample in attach "Sin título2.png"
This my actual Code
//My principal fucntion:
public voidCreateGraf01()
{
SpireHelpers spireHelpers = new SpireHelpers();
Workbook workbook = new Workbook();
//Initailize worksheet
workbook.CreateEmptySheets(1);
Worksheet sheet = workbook.Worksheets[0];
sheet.Name = "TRA";
sheet.GridLinesVisible = false;
//Writes chart data
CreateChartData(sheet);
//Add a new chart worsheet to workbook
Chart chart = sheet.Charts.Add();
chart.ChartType = ExcelChartType.Line;
//Set position of chart
chart.LeftColumn = 1;
chart.TopRow = 6;
chart.RightColumn = 11;
chart.BottomRow = 29;
//Chart title
chart.ChartTitle = "";
//Set region of chart data
chart.DataRange = sheet.Range["B1:H2"];
chart.SeriesDataFromRange = true;
Spire.Xls.Charts.ChartSerie cs = chart.Series[0];
//Chart Labels resource
cs.CategoryLabels = sheet.Range["B1:H1"];
//Chart value resource
cs.Values = sheet.Range["B2:H2"];
cs.UsePrimaryAxis = true;
//Division Lines
chart.PrimaryCategoryAxis.HasMajorGridLines = true;
chart.PrimaryCategoryAxis.HasMinorGridLines = true;
chart.PrimaryValueAxis.HasMajorGridLines = true;
chart.PrimaryValueAxis.HasMinorGridLines = true;
chart.SecondaryCategoryAxis.HasMajorGridLines = true;
chart.SecondaryCategoryAxis.HasMinorGridLines = true;
chart.SecondaryValueAxis.HasMajorGridLines = true;
chart.SecondaryValueAxis.HasMinorGridLines = true;
//Division Lines Color
chart.PrimaryValueAxis.MajorGridLines.LineProperties.Color = Color.Red;
chart.PrimaryValueAxis.MinorGridLines.LineProperties.Color = Color.Black;
chart.PrimaryCategoryAxis.MajorGridLines.LineProperties.Color = Color.Red;
chart.PrimaryCategoryAxis.MinorGridLines.LineProperties.Color = Color.Black;
chart.PrimaryCategoryAxis.CrossValue = 0;
chart.PrimaryValueAxis.CrossValue = 0;
chart.SecondaryCategoryAxis.CrossValue = 0;
chart.SecondaryValueAxis.CrossValue = 0;
//Chart Axes
chart.PrimaryCategoryAxis.Title = "%Elongación";
chart.PrimaryCategoryAxis.LabelFrequency = 1;
chart.PrimaryCategoryAxis.MinValue = 0;
chart.PrimaryCategoryAxis.MaxValue = 6;
chart.PrimaryCategoryAxis.Font.Color = Color.Black;
chart.PrimaryValueAxis.IsReverseOrder = false;
chart.PrimaryValueAxis.Title = "Fuerza (KN)";
chart.PrimaryValueAxis.IsAutoCross = true;
chart.PrimaryValueAxis.MinValue = 0;
chart.PrimaryValueAxis.MaxValue = 140;
chart.PrimaryValueAxis.CrossesAt = 0;
chart.PrimaryValueAxis.TitleArea.TextRotationAngle = 0;
chart.SecondaryCategoryAxis.Title = "Fuerza1 (KN)";
chart.SecondaryValueAxis.Title = "SecondaryValueAxis";
chart.PrimaryValueAxis.TitleArea.IsBold = true;
chart.PlotArea.Visible = false;
chart.Legend.Delete();
workbook.SaveToFile(@"D:\TEMP\IMAGES\GRAF_001.xlsx");
}
// My data
private void CreateChartData(Worksheet sheet)
{
sheet.Range["B1"].Value = "0";
sheet.Range["B2"].NumberValue = 0;
sheet.Range["C1"].Value = "1";
sheet.Range["C2"].NumberValue = 7.5;
sheet.Range["D1"].Value = "2";
sheet.Range["D2"].NumberValue = 7.7;
sheet.Range["E1"].Value = "3";
sheet.Range["E2"].NumberValue = 8;
sheet.Range["F1"].Value = "4";
sheet.Range["F2"].NumberValue = 98;
sheet.Range["G1"].Value = "5";
sheet.Range["G2"].NumberValue = 100;
sheet.Range["H1"].Value = "6";
sheet.Range["H2"].NumberValue = 110;
sheet.Range["B2:H2"].Style.NumberFormat = "0.0"; //"\"$\"#,##0";
}
Thanks.