Hello team,
I am trying to build a line chart where the X Axis has a MajorUnitScale = TimeUnitType.Months but the available data starts on the 26th of April. There is also an interval of 3 (months) but that is irrelevant to the problem.
This is making the X axis deviate from the tick marks to the left:
Actual Behaviour (Aspose).png (69.5 KB)
I have tried everything, including replicating the chart with the same data on excel and mimicking the settings to the project:
Expected Behaviour (Excel).png (13.2 KB)
Setings (Excel).png (4.4 KB)
Settings (Aspose).png (5.8 KB)
I strongly believe this is a bug. Can someone please verify?
@muchagato,
Thank you for contacting support.
Please check your results using the latest version of Aspose.Slides if it is possible. If the issue persists, please share the following data and information:
- input and output files (you can zip the files and upload an archive here)
- comprehensive code example (as text) creating the chart
- OS version on which the code was executed
- .NET target platform in your app
- Aspose.Slides version you used
Hello,
I just updated to the latest version of Aspose.Slides and the problem persists.
-
Input and output file I don’t think are important as they’re just a ppt with an image, but here’s a screenshot of the result:
Result.png (71.4 KB)
-
Code for styling the X axis:
chart.Axes.HorizontalAxis.CategoryAxisType = CategoryAxisType.Date;
chart.Axes.HorizontalAxis.IsAutomaticMajorUnit = false;
chart.Axes.HorizontalAxis.MajorUnit = intervalUnit;
chart.Axes.HorizontalAxis.MajorUnitScale = unitScale;
chart.Axes.HorizontalAxis.BaseUnitScale = TimeUnitType.Days;
chart.Axes.HorizontalAxis.MinValue = earliestDate.ToOADate();
chart.Axes.HorizontalAxis.NumberFormat = "MMM-yy";
Where
intervalUnit = 3
unitScale = TimeUnitType.Months
earliestDate = {4/26/2021 12:00:00 AM}
@muchagato,
Please share the complete code example that creates the chart.
Hello,
Sorry for the delay. I had to make a dummy program as the original is spread out over a multitude of methods. In the process I made a few more discoveries. It seems like the ppt actually generates properly, it is the getThumbnail() method that is somehow changing the properties of the shape.
Result taken from pptx.png (79.0 KB)
Chart GetThumbnail Save.png (26.5 KB)
Here’s the code, as requested:
static void Main(string[] args)
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
var stream = File.OpenRead("data0.csv");
IExcelDataReader reader = ExcelDataReader.ExcelReaderFactory.CreateCsvReader(stream);
var result = reader.AsDataSet();
List<DateTime> dates = result.Tables[0].AsEnumerable().Select(
r => DateTime.Parse(r.Field<string>(0), new CultureInfo("en-US"))
).ToList();
List<double> values = result.Tables[0].AsEnumerable().Select(r => Double.Parse(r.Field<string>(1))).ToList();
Presentation presentation = new Presentation();
ISlide slide = presentation.Slides[0];
IChart chart = slide.Shapes.AddChart(ChartType.Line, 10, 50, 900, 1200);
IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook;
chart.ChartData.Series[0].Labels.DefaultDataLabelFormat.ShowValue = true;
// Y Axis Styling
chart.Axes.VerticalAxis.IsAutomaticMinValue = false;
chart.Axes.VerticalAxis.MinValue = Math.Floor(values.Min());
// X Axis Syling
chart.Axes.HorizontalAxis.IsNumberFormatLinkedToSource = false;
chart.Axes.HorizontalAxis.CategoryAxisType = CategoryAxisType.Date;
chart.Axes.HorizontalAxis.IsAutomaticMajorUnit = false;
chart.Axes.HorizontalAxis.MajorUnit = 3;
chart.Axes.HorizontalAxis.MajorUnitScale = TimeUnitType.Months;
chart.Axes.HorizontalAxis.BaseUnitScale = TimeUnitType.Days;
chart.Axes.HorizontalAxis.NumberFormat = "dd-MMM-yy";
chart.ChartData.Series.Clear();
chart.ChartData.Categories.Clear();
// Populate Values
chart.ChartData.Series.Add(wb.GetCell(0, 0, 0, "Values"), chart.Type);
int row = 1;
foreach (double value in values)
{
IChartDataCell cell = wb.GetCell(0, row, 0, value);
chart.ChartData.Series[0].DataPoints.AddDataPointForLineSeries(cell);
row++;
}
// Populate Dates
foreach (DateTime date in dates)
chart.ChartData.Categories.Add(date.ToOADate());
// General Styling
chart.Axes.VerticalAxis.MajorGridLinesFormat.Line.FillFormat.FillType = FillType.NoFill;
chart.FillFormat.FillType = FillType.Solid;
chart.FillFormat.SolidFillColor.Color = Color.White;
chart.Legend.Position = LegendPositionType.Bottom;
// Saving
presentation.Save("test.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
Bitmap chartBitmap = chart.GetThumbnail(ShapeThumbnailBounds.Shape, 1, 1);
chartBitmap.Save("image.png", ImageFormat.Png);
}
@muchagato,
Thank you for the sample code. I am working on the issue you described and will get back to you a bit later.
@muchagato,
Unfortunately, I have not managed to reproduce the problem you described. Please note that your code example contains an unknown IExcelDataReader
interface, ExcelDataReader
property, and data0.csv file name. Please try to isolate the problem and share anything we need to reproduce the issue on our end.
The ExcelDataReader.DataSet is a package that you can download from nuget used only to read the data from the data0.csv file. I use this data to feed the series and categories of the chart instead of hardcoding hundreds of dates and values.
Please try using the bellow dummy data to reproduce the issue:
data0.zip (1.5 KB)
After running the program check the generated image.png and you should be able to verify the problem.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): SLIDESNET-43734
You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.
The issues you found earlier (filed as SLIDESNET-43734) have been fixed in Aspose.Slides for .NET 23.7 (ZIP, MSI).
You can check all fixes on the Release Notes page.
You can also find the latest version of our library on the Product Download page.
1 Like