Profile Picture

Barchart size problem when we have dynamic data

Posted By Jebarson Rajin 15 Years Ago
Author
Message
Jebarson Rajin
crazy Posted 15 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: Forum Members
Last Active: 15 Years Ago
Posts: 6, Visits: 1
Hi,

I am trying to bind few data into a bar chart where I wish to keep the bar width a constant where as the width and chart dynamic based on the content of the data.

Say if I need to bind 10 data, my chart height need to be 200px keeping my bar width 15 per data.
if I need to bind 20 data, my chart height need to be 350px keeping my bar width 15 per data.

But since the nchart is getting a model unit which I am unable to figure out the usage. I tried to apply some calculation, which didn't help me and it is resulting in a total disfigure of the size. Please help on this and my project is urgently relying on this.

bob milanov
Posted 15 Years Ago
View Quick Profile
Supreme Being

Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)

Group: Forum Members
Last Active: 6 Months Ago
Posts: 153, Visits: 11

Hi Jebarson,

 

Please excuse us for the delayed response.

 

Generally it's quite easy to do this - the only thing that you need to know is the number of data points. The following code shows how to export bars roughly 15 pixels wide to the clipboard:

 

nChartControl1.Panels.Clear();

 

NCartesianChart chart = new NCartesianChart();

chart.Dock = DockStyle.Fill;

 

NLength margin = new NLength(10, NGraphicsUnit.Pixel);

chart.BoundsMode = BoundsMode.Stretch;

chart.Margins = new NMarginsL(margin, margin, margin, margin);

 

Random rand = new Random();

int dataPointCount = 20;

 

NBarSeries bar = new NBarSeries();

bar.DataLabelStyle.Visible = false;

 

for (int i = 0; i < dataPointCount; i++)

{

    bar.Values.Add(rand.Next(100));

}

 

chart.Series.Add(bar);

 

nChartControl1.Panels.Add(chart);

 

int pixelPerBar = 15;

int distance = 5;

 

int width = dataPointCount * (pixelPerBar + distance) + 2 * (int)margin.Value;

bar.WidthPercent = (float)pixelPerBar * 100.0f / (float)(pixelPerBar + distance);

 

nChartControl1.ImageExporter.CopyToClipboard(new NSize(width, width), NResolution.ScreenResolution, new NBitmapImageFormat());

The general idea is to use docked and stretched chart - this way you have a chart that fills the whole control area minus some margins (set to 10px in the above code). The width of the bars is controlled trough the WidthPercent property in the case of a categorical bar chart. If you want to use scatter you need to set the BarWidth property.

 

Hope this helps - let me know if you meet any problems.

 

Best regards,
Bob



Jebarson Rajin
Posted 15 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: Forum Members
Last Active: 15 Years Ago
Posts: 6, Visits: 1
I am now getting the problem of axis labels not staying within the chart. I have attached the chart. Please help.

I am using ASP.net and not windows application

Attachments
untitled.PNG (43 views, 7.00 KB)
Jebarson Rajin
Posted 15 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: Forum Members
Last Active: 15 Years Ago
Posts: 6, Visits: 1
Hi there,

The output seems much worse. I have attached the snapshot when I have 16 records in my chart.


Attachments
NevronChart.axd.png (38 views, 22.00 KB)
bob milanov
Posted 15 Years Ago
View Quick Profile
Supreme Being

Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)

Group: Forum Members
Last Active: 6 Months Ago
Posts: 153, Visits: 11

Hi Jebarson,

I'm not quite sure but I think you're using the chart in 3D mode - in this case you also have to enable 3D axis content fitting:

NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];
chart.Fit3DAxisContent =
true;

and to adjust the chart aspect if it's not a square.

In general I would recommend you to use 2D mode for this type of chart as the produced image will be more clear (the axis ticks in 2D use pixel snapping).

Hope this helps - let me know if you meet any problems.

Best regards,
Bob

 





Similar Topics


Reading This Topic