We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

ValueAxis.MajorUnit in Charts


We are using Aspose charts in our application. For the bar charts, we are setting the chart.ValueAxis.MinValue and chart.ValueAxis.MaxValue depending on the data we have, which is working perfectly fine.

Now we want to set the intervals for chart’s value axis also and I have seen the properties chart.ValueAxis.MinorUnit and chart.ValueAxis.MajorUnit but I am not sure what the exact difference between those and so not sure how to use them. Can you please elaborate with some examples?
Our charts are something like attached.

<!–[if !mso]>

v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);}

<![endif]–><!–[if gte mso 9]>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;}



I have written an example code for your reference, please refer to it with comments for your reference. I have also attached the screen shot to show the difference b/w major and minor units for your reference.
Sample code:

Workbook workbook = new Workbook();
workbook.ChangePalette(Color.Orange, 55);

//Set default font
Style style = workbook.DefaultStyle;
style.Font.Name = “Tahoma”;
workbook.DefaultStyle = style;
Cells cells = workbook.Worksheets[0].Cells;

//Put a string into a cell

cells[“B1”].PutValue(“Marketing Costs”);

Worksheet sheet = workbook.Worksheets[0];
sheet.IsGridlinesVisible = false;

Worksheet sheet1 = workbook.Worksheets[workbook.Worksheets.Add(SheetType.Chart)];
//Create chart
int chartIndex = sheet1.Charts.Add(ChartType.Bar, 5, 1, 29, 10);
Chart chart = sheet1.Charts[chartIndex];

//Add the nseries collection to a chart
chart.NSeries.Add(“Sheet1!B2:B4”, true);
//Get or set the range of category axis values
chart.NSeries.CategoryData = “Sheet1!A2:A4”;
chart.NSeries.IsColorVaried = true;

for (int i = 0; i < chart.NSeries.Count; i++)
chart.NSeries[i].DataLabels.ShowValue = true;
chart.NSeries[i].Area.ForegroundColor = Color.Blue;
chart.NSeries[i].Line.Color = Color.Red;
chart.NSeries[i].Line.Style = LineType.Solid;
chart.NSeries[i].Line.Weight = WeightType.MediumLine;

//Set properties of chart
chart.ChartArea.Border.IsVisible = false;
chart.ChartArea.Area.ForegroundColor = Color.Transparent;

//Set the legend position type
chart.Legend.Position = LegendPositionType.Top;
chart.GapWidth = int.Parse(“100”);
// chart.MajorGridLines.IsVisible = false;

//Set properties of chart title
chart.Title.Text = “Marketing Costs by Region”;
chart.Title.TextFont.IsBold = true;
chart.Title.TextFont.Color = Color.Black;
chart.Title.TextFont.Size = 12;

//Set properties of categoryaxis title
chart.CategoryAxis.Title.Text = “Region”;
chart.CategoryAxis.Title.TextFont.Color = Color.Black;
//Set properties of valueaxis title
chart.ValueAxis.Title.Text = “In Thousands”;
chart.ValueAxis.Title.TextFont.Name = “Arial”;
chart.ValueAxis.Title.TextFont.Color = Color.Black;
chart.ValueAxis.Title.TextFont.IsBold = true;
chart.ValueAxis.Title.TextFont.Size = 10;
chart.ValueAxis.MajorUnit = double.Parse(“20000”);
chart.ValueAxis.MaxValue = double.Parse(“80000”);
chart.ValueAxis.MinorUnit = double.Parse(“5000”);
chart.ValueAxis.MinValue = double.Parse(“0”);

//To understand Major and minor units and to see the major and minor units precisely, you need to set the major and minor tick marks types shown properly.
chart.ValueAxis.MajorTickMark = TickMarkType.Outside;
chart.ValueAxis.MinorTickMark = TickMarkType.Inside;


Hope, this helps a bit.

Thank you.

Thanks Amjad for such a quick response.
I got your point and in my case, I think I need to use only MajorUnit. No need to bother about the Minor one.

Thanks again…!!


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

Thank you.