jeudi 26 mars 2015

Aspose Chart in excel with DateTime on category axis

Hi I am trying to create a chart with aspose I want date with time on category axis. I am getting only date on category axis bellow is my code. I want to create a weekly chart so on category axis it will display dates and between two dates there will be 24 points so i will indelicate the hours.



int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.LineWithDataMarkers, 2, 10, 20, 30);

//Accessing the instance of the newly added chart
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
int seriesCount = 0;

string wallboardRecordCount = (wallboardStat.Count + 1).ToString();
decimal? maxVal = 0;
if (Avg_TotalAgents == "1")
{
// chart.NSeries.Add("G1:G" + wallboardStat.Count, true);
Series aSerie = chart.NSeries[chart.NSeries.Add("G2:G" + wallboardRecordCount, true)];
aSerie.XValues = String.Format("{0}!{1}{2}:{1}{3}", worksheet.Name, "A", 2, wallboardStat.Count + 1);
chart.NSeries[seriesCount].Name = "Avg_TotalAgents";
seriesCount++;
maxVal = wallboardStat.Select(s => s.Avg_TotalAgents).Max();
}
if (Avg_AvailAgents == "1")
{
//chart.NSeries.Add("H1:H" + wallboardStat.Count, true);
Series aSerie = chart.NSeries[chart.NSeries.Add("H2:H" + wallboardRecordCount, true)];
aSerie.XValues = String.Format("{0}!{1}{2}:{1}{3}", worksheet.Name, "A", 2, wallboardStat.Count + 1);
chart.NSeries[seriesCount].Name = "Avg_AvailAgents";
seriesCount++;

if (wallboardStat.Select(s => s.Avg_AvailAgents).Max() > maxVal)
{
maxVal = wallboardStat.Select(s => s.Avg_AvailAgents).Max();
}
}
if (Avg_CallsQueued == "1")
{
// chart.NSeries.Add("I1:I" + wallboardStat.Count, true);
Series aSerie = chart.NSeries[chart.NSeries.Add("I2:I" + wallboardRecordCount, true)];
aSerie.XValues = String.Format("{0}!{1}{2}:{1}{3}", worksheet.Name, "A", 2, wallboardStat.Count + 1);
chart.NSeries[seriesCount].Name = "Avg_CallsQueued";
seriesCount++;

if (wallboardStat.Select(s => s.Avg_CallsQueued).Max() > maxVal)
{
maxVal = wallboardStat.Select(s => s.Avg_CallsQueued).Max();
}
}


chart.NSeries.CategoryData = "A2:A" + wallboardStat.Count + 1;
chart.CategoryAxis.CategoryType = Aspose.Cells.Charts.CategoryType.TimeScale;
chart.CategoryAxis.BaseUnitScale = Aspose.Cells.Charts.TimeUnit.Days;
chart.CategoryAxis.MajorUnitScale = Aspose.Cells.Charts.TimeUnit.Months;
chart.CategoryAxis.IsAutomaticMajorUnit = true;


In excel "A" column contains datetime


Aucun commentaire:

Enregistrer un commentaire