PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 10:36 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Jun 27, 2016 8:18 am 
Offline

Joined: Mon Jun 27, 2016 7:32 am
Posts: 3
Hello,

I am creating a chart using the example given in (DefineCharts is called by CreateDocument):
http://www.pdfsharp.net/wiki/HelloMigraDoc-sample.ashx

However the x-axis in this example are strings, and my data is of type double. I converted the a double array to string array and added it to XSeries of the chart.

The problem is that the x-ticks are displayed for every value in the XSeries, I want to set the x-ticks to something like 2.0 or 10.0, setting a value to chart.XAxis.MajorTick does not have any effect.

Can anyone tell me how to set the Major ticks so that the values on x-axis are readable ?

What I expect to see is values for x which are spaced evenly in steps like 45, 55, 65, 75...... Currently all the values in values_X here displayed along the x-axis.

See the code example:
Code:
// Input data: values_Y and values_X are double arrays
Chart chart = new Chart();
chart.Left = 0;
chart.Width = Unit.FromCentimeter(16);
chart.Height = Unit.FromCentimeter(12);
Series series = chart.SeriesCollection.AddSeries();
series.ChartType = ChartType.Line;

series.Add(values_Y);
XSeries xseries = chart.XValues.AddXSeries();

foreach (var value in values_X)
{
     xseries.Add(value.ToString());
}

chart.XAxis.MajorTick = 10.0;   // Setting the MajorTick here which does not have any effect !
chart.XAxis.MajorTickMark = TickMarkType.Outside;
chart.XAxis.Title.Caption = "X-Axis";


chart.YAxis.MajorTick = 10.0;
chart.YAxis.MajorTickMark = TickMarkType.Outside;
chart.YAxis.HasMajorGridlines = true;
chart.PlotArea.LineFormat.Color = Colors.DarkGray;
chart.PlotArea.LineFormat.Width = 1;

document.LastSection.Add(chart);



By the way the x values do not start from 0.


Last edited by supandi112 on Fri Sep 23, 2016 9:28 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 13, 2016 11:53 pm 
Offline

Joined: Wed Jul 13, 2016 11:47 pm
Posts: 1
Code:
XSeries xseries = chart.XValues.AddXSeries();
string[] xSeriesText = new string[dataSet.Length];
 for (int i = 0; i < dataSet.Length; i++)
{
     xSeriesText[i] = ((i%10)==0) ? i.ToString() : string.Empty;
}
 xseries.Add(xSeriesText);


You need to assign the values for xSeries. The above code is an example where I only show every 10 marks. You can change the 10 to be any number you would like. Note that you must use string.empty for values you do not want to display, "" will still have overlap and potentially hide all of your marks.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 15, 2016 12:19 pm 
Offline

Joined: Mon Jun 27, 2016 7:32 am
Posts: 3
thanks, it works.
However it would be good if charts supported double type in x series instead of just strings, so that simply setting the Major ticks would do the job.

Best Regards


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 159 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group