Free Support Forum - aspose.com

Integer numbers in axis y (c#)

i have a function to extract a line chart made with aspose.cells. ¿how can I put integers numbers only in the axis y?. Actually , the chart show decimals (25.5, 24.5 etc)


I put my code also:
internal string createLineChart(Dictionary<string, Double> parametros, double dMinValorAxis = -1, double dMaxValorAxis = -1, bool bMostrar = false)
{

//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Excel object
int sheetIndex = workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by
//passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];


/*
string slistaDireccionValParticipacion = “7,18509;7,18552;7,18595;7,2;7,19347;7,18314;7,18383;7,19728;7,19771;7,19813;7,20488;7,20692;7,21304;7,21601;7,21994;7,22036;7,22079;7,21169;7,21211;7,21574;7,21869;7,22513;7,22556;7,22598;7,24319;7,24044;7,22506;7,21186;7,21641;7,21684;7,21726”;
string slistaCabeceraFechas = “2014.08.01;2014.08.02;2014.08.03;2014.08.04;2014.08.05;2014.08.06;2014.08.07;2014.08.08;2014.08.09;2014.08.10;2014.08.11;2014.08.12;2014.08.13;2014.08.14;2014.08.15;2014.08.16;2014.08.17;2014.08.18;2014.08.19;2014.08.20;2014.08.21;2014.08.22;2014.08.23;2014.08.24;2014.08.25;2014.08.26;2014.08.27;2014.08.28;2014.08.29;2014.08.30;2014.08.31”;

string [] listaDireccionValParticipacion = slistaDireccionValParticipacion.Split(’;’);
string [] listaCabeceraFechas = slistaCabeceraFechas.Split(’;’);


for (int i=0 ; i < listaDireccionValParticipacion.Count();i++)
{
parametros.Add(listaCabeceraFechas[i].ToString(), Convert.ToDouble(listaDireccionValParticipacion[i].ToString()));
}
/

double dMinValor = parametros.Values.Min();
double dMaxValor = parametros.Values.Max();


int iRowActual = 0;


foreach (KeyValuePair<string, double> pair in parametros)
{
iRowActual++;
if (bMostrar)
{
worksheet.Cells[iRowActual, 0].PutValue(pair.Key);
}
else
{
worksheet.Cells[iRowActual, 0].PutValue("");
}
worksheet.Cells[iRowActual, 1].PutValue(pair.Value);
}

// double parametros.Max
/ //Adding a sample value to “A1” cell
worksheet.Cells[“A1”].PutValue(80);
//Adding a sample value to “A2” cell
worksheet.Cells[“A2”].PutValue(67);
//Adding a sample value to “A3” cell
worksheet.Cells[“A3”].PutValue(99);
//Adding a sample value to “B1” cell
worksheet.Cells[“B1”].PutValue(4);
//Adding a sample value to “B2” cell
worksheet.Cells[“B2”].PutValue(20);
//Adding a sample value to “B3” cell
worksheet.Cells[“B3”].PutValue(50);

//Adding a chart to the worksheet*/

int upLeftRow = 1;
int upLeftCol = 1;
int lwrRightRow = 12;
int lwrRightCol = 6;
// int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 0, 15, 05);
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Line, upLeftRow, upLeftCol, lwrRightRow, lwrRightCol);
//Accessing the instance of the newly added chart
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
//Adding Series Collection (chart data source) to the chart ranging from “A1” cell to “B3”
chart.NSeries.Add(CellsHelper.CellIndexToName(1, 1) + “:” + CellsHelper.CellIndexToName(iRowActual, 1), true);
chart.NSeries.CategoryData = CellsHelper.CellIndexToName(1, 0) + “:” + CellsHelper.CellIndexToName(iRowActual, 0);
chart.NSeries.IsColorVaried = true;

chart.ChartArea.Width = 300;
chart.ChartObject.Width = 290;


System.IO.Stream fs = new MemoryStream();


if (dMinValor == -1)
{

// chart.ChartArea.BackgroundMode = Aspose.Cells.Charts.BackgroundMode.Transparent;
double margen = Math.Abs((dMaxValor - dMinValor) / 2);

if (margen < 0.4)
{
margen = 0.4;
}

if ((dMinValor - margen) < 0)
{
chart.ValueAxis.MinValue = 0;
}
else
{
chart.ValueAxis.MinValue = dMinValor - margen;
}
chart.ValueAxis.MaxValue = dMaxValor + margen;
}
else
{
chart.ValueAxis.MinValue = dMinValorAxis;
chart.ValueAxis.MaxValue = dMaxValorAxis;
}




//Setting the foreground color of the plot area
chart.PlotArea.Area.ForegroundColor = Color.White;

// chart.NSeries[0].SeriesLines.Color = Color.Fuchsia;
chart.NSeries[0].SeriesLines.DashType = Aspose.Cells.Drawing.MsoLineDashStyle.Solid;
chart.NSeries[0].SeriesLines.Weight = Aspose.Cells.Drawing.WeightType.WideLine;

chart.NSeries[0].Border.Color = Color.Green;
chart.NSeries[0].Border.Weight = Aspose.Cells.Drawing.WeightType.MediumLine;
chart.ShowLegend = false;

chart.ValueAxis.MajorGridLines.Color = Color.FromArgb(192, 192, 192);
chart.ChartDataTable.ShowLegendKey = false;
chart.Title.Text = “”;
chart.ChartArea.Border.IsVisible = false;
chart.ChartArea.Font.Size = 7;
chart.ToImage(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
// System.IO.Stream fs = FileUpload1.PostedFile.InputStream;
System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
br.BaseStream.Position = 0;
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
//Image1.ImageUrl = “data:image/png;base64,” + base64String;
//Image1.Visible = true;*/

return base64String;
}

Hi,


Thanks for providing us some details and sample code segment.

I think you may try to use chart.ValueAxis.MajorUnit to set to 1 if it makes any difference.

Also, I tried to evaluate your sample code but I am not sure about some of your objects or their values, e.g collection object/variable parametros etc. So, if the above suggestion does not resolve your issue, kindly provide us a sample console application (runnable), zip it and post us here to evaluate your issue properly, we will check and help you to accomplish your task soon.

Thank you.


it´s correct!!!

Many thanks for all

Hi,


Good to know that it figures out your issue now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.