Custom Marker Shape

Hi,

I wants to use custom shape markers for series. But i wants to use icon files to create custom markers. so that i can fill them with desire colors as my requirement is to use same marker image with different different colors.


Please provide me the solution for the problem.

Thanks,
Amit

Hi,


See the sample code that demonstrates on how to apply different colors to same marker styles in the chart.

Sample code:

Workbook excel = new Workbook();
Worksheet sheet = excel.Worksheets[0];
Cells cells = excel.Worksheets[0].Cells;
cells[“A1”].PutValue(“Daily Rainfall”);
cells[“B1”].PutValue(“Particulate”);
cells[“A2”].PutValue(1.9);
cells[“B2”].PutValue(45);
cells[“A3”].PutValue(3.6);
cells[“B3”].PutValue(128);
cells[“A4”].PutValue(4.1);
cells[“B4”].PutValue(122);
cells[“A5”].PutValue(4.3);
cells[“B5”].PutValue(87);
cells[“A6”].PutValue(5);
cells[“B6”].PutValue(114);
cells[“A7”].PutValue(5.4);
cells[“B7”].PutValue(65);
cells[“A8”].PutValue(5.7);
cells[“B8”].PutValue(112);
cells[“A9”].PutValue(5.9);
cells[“B9”].PutValue(110);
cells[“A10”].PutValue(7.3);
cells[“B10”].PutValue(94);
excel.Worksheets.Add(SheetType.Chart);
ChartCollection charts = excel.Worksheets[1].Charts;
int chartIndex = charts.Add(ChartType.LineWithDataMarkers, 1, 3, 25, 12);
Chart chart = charts[chartIndex];

chart.Legend.Position = LegendPositionType.Top;
chart.Title.Text = “Line chart:Particulate Levels in Rainfall”;
chart.Title.TextFont.Color = Color.Black;
chart.Title.TextFont.IsBold = true;
chart.Title.TextFont.Size = 12;
chart.ValueAxis.MinValue = 30;
chart.ValueAxis.MaxValue = 200;
chart.NSeries.Add(“Sheet1!B2:B10”, true);
chart.NSeries[0].XValues = “Sheet1!A2:A10”;

SeriesCollection nseries = chart.NSeries;

string seriesval = nseries[0].Values;
int index = seriesval.IndexOf(’!’);
index++;
MessageBox.Show(index.ToString());
string val = seriesval.Substring(index, seriesval.Length - index);
MessageBox.Show(val.ToString());

string[] strCellRange = val.Replace("$", “”).Split(’:’);
int frow, fcol, lrow, lcol;
CellsHelper.CellNameToIndex(strCellRange[0], out frow, out fcol);
CellsHelper.CellNameToIndex(strCellRange[1], out lrow, out lcol);
//Applying some conditional Markers formattings (marker’s foreground and background colors) having same marker styles (Square here)
int i = 0;
for (int r = frow; r <= lrow; r++)
{
for (int c = fcol; c <= lcol; c++)
{
if (cells[r, c].IntValue > 100)
{
nseries[0].Points[i].MarkerStyle = ChartMarkerType.Square;
nseries[0].Points[i].MarkerBackgroundColor = Color.Red;
nseries[0].Points[i].MarkerForegroundColor = Color.Blue;
nseries[0].Points[i].MarkerSize = 8;

}
else
{

nseries[0].Points[i].MarkerStyle = ChartMarkerType.Square;
nseries[0].Points[i].MarkerBackgroundColor = Color.Blue;
nseries[0].Points[i].MarkerForegroundColor = Color.Red;
nseries[0].Points[i].MarkerSize = 8;

}
i++;
}

}


chart.CategoryAxis.Title.Text = cells[“A1”].Value.ToString();
chart.ValueAxis.Title.Text = cells[“B1”].Value.ToString();

excel.Save(“e:\test2\outlinemarkers_charttest2.xls”);

Hope, it will help you and you may customize/change the code accordingly for your needs.

And regarding: "I wants to use custom shape markers for series. But i wants to use icon files to create custom markers. so that i can fill them with desire colors as my requirement"

I am not sure if this can be done in MS Excel either. I think this cannot be done in MS Excel. If you know the procedure on how to do it in MS Excel, kindly share all the steps and attach sample Excel file (by manually created in MS Excel), we will check it soon.


Thank you.

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

I have checked this issue earlier too and I think, this feature is not currently available or if it is available, we need to find out how to use any picture (or icon) as a custom marker.

I have attached the source file and the screenshot below explaining the requirement for your reference.

We have logged this issue in our database. We will look into it and implement this feature or provide you a solution. Once the fix/solution is available or we have some other update for you, we will let you know asap.

This issue has been logged as CELLSNET-40918.

Screenshot:

Hi,

Please download and try this fix: Aspose.Cells for .NET v7.3.0.3

We have added a Marker object for supporting marker feature. Please refer to the attached code segment.

The issues you have found earlier (filed as CELLSNET-40918) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.