C# desktop chart draw complete takes long time












0















I am creating C# chart using button click.



    void myButton_Click(object sender, RoutedEventArgs e)
{
DrawChart();
MessageBox.Show("Draw complated");
}

private void DrawChart()
{
for (int i = 0; i < 30000; i++)
{
Series series = this.chart1.Series.Add(seriesArray[i]);
series.Points.Add(pointsArray[i]);
}
}


I have about 30000 points. So when I click the button, the message box shows immediately, but the graphic is drawn after 5-10 seconds. The users gets the message box before but there is no chart on chart area about 10 seconds.



How can I solve this problem?










share|improve this question

























  • use less points or maybe cashe the chart result if that is possible

    – Slai
    Nov 27 '18 at 18:59













  • Data is 30000, so I should use data count. Is there any property of chart to use 1000 points of these 30000 points?

    – barteloma
    Nov 27 '18 at 19:01













  • I mean to add less points to the chart if the speed is the problem. For example, adding every 30th point by replacing i++ with i += 30

    – Slai
    Nov 27 '18 at 19:27











  • Why do you add so many Series??? That is not what series is made for! 30k points is even a lot but series??? Why would you use more than one series??

    – TaW
    Nov 27 '18 at 19:56


















0















I am creating C# chart using button click.



    void myButton_Click(object sender, RoutedEventArgs e)
{
DrawChart();
MessageBox.Show("Draw complated");
}

private void DrawChart()
{
for (int i = 0; i < 30000; i++)
{
Series series = this.chart1.Series.Add(seriesArray[i]);
series.Points.Add(pointsArray[i]);
}
}


I have about 30000 points. So when I click the button, the message box shows immediately, but the graphic is drawn after 5-10 seconds. The users gets the message box before but there is no chart on chart area about 10 seconds.



How can I solve this problem?










share|improve this question

























  • use less points or maybe cashe the chart result if that is possible

    – Slai
    Nov 27 '18 at 18:59













  • Data is 30000, so I should use data count. Is there any property of chart to use 1000 points of these 30000 points?

    – barteloma
    Nov 27 '18 at 19:01













  • I mean to add less points to the chart if the speed is the problem. For example, adding every 30th point by replacing i++ with i += 30

    – Slai
    Nov 27 '18 at 19:27











  • Why do you add so many Series??? That is not what series is made for! 30k points is even a lot but series??? Why would you use more than one series??

    – TaW
    Nov 27 '18 at 19:56
















0












0








0








I am creating C# chart using button click.



    void myButton_Click(object sender, RoutedEventArgs e)
{
DrawChart();
MessageBox.Show("Draw complated");
}

private void DrawChart()
{
for (int i = 0; i < 30000; i++)
{
Series series = this.chart1.Series.Add(seriesArray[i]);
series.Points.Add(pointsArray[i]);
}
}


I have about 30000 points. So when I click the button, the message box shows immediately, but the graphic is drawn after 5-10 seconds. The users gets the message box before but there is no chart on chart area about 10 seconds.



How can I solve this problem?










share|improve this question
















I am creating C# chart using button click.



    void myButton_Click(object sender, RoutedEventArgs e)
{
DrawChart();
MessageBox.Show("Draw complated");
}

private void DrawChart()
{
for (int i = 0; i < 30000; i++)
{
Series series = this.chart1.Series.Add(seriesArray[i]);
series.Points.Add(pointsArray[i]);
}
}


I have about 30000 points. So when I click the button, the message box shows immediately, but the graphic is drawn after 5-10 seconds. The users gets the message box before but there is no chart on chart area about 10 seconds.



How can I solve this problem?







c# .net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 '18 at 20:04









marc_s

580k13011191266




580k13011191266










asked Nov 27 '18 at 18:44









bartelomabarteloma

2,04942983




2,04942983













  • use less points or maybe cashe the chart result if that is possible

    – Slai
    Nov 27 '18 at 18:59













  • Data is 30000, so I should use data count. Is there any property of chart to use 1000 points of these 30000 points?

    – barteloma
    Nov 27 '18 at 19:01













  • I mean to add less points to the chart if the speed is the problem. For example, adding every 30th point by replacing i++ with i += 30

    – Slai
    Nov 27 '18 at 19:27











  • Why do you add so many Series??? That is not what series is made for! 30k points is even a lot but series??? Why would you use more than one series??

    – TaW
    Nov 27 '18 at 19:56





















  • use less points or maybe cashe the chart result if that is possible

    – Slai
    Nov 27 '18 at 18:59













  • Data is 30000, so I should use data count. Is there any property of chart to use 1000 points of these 30000 points?

    – barteloma
    Nov 27 '18 at 19:01













  • I mean to add less points to the chart if the speed is the problem. For example, adding every 30th point by replacing i++ with i += 30

    – Slai
    Nov 27 '18 at 19:27











  • Why do you add so many Series??? That is not what series is made for! 30k points is even a lot but series??? Why would you use more than one series??

    – TaW
    Nov 27 '18 at 19:56



















use less points or maybe cashe the chart result if that is possible

– Slai
Nov 27 '18 at 18:59







use less points or maybe cashe the chart result if that is possible

– Slai
Nov 27 '18 at 18:59















Data is 30000, so I should use data count. Is there any property of chart to use 1000 points of these 30000 points?

– barteloma
Nov 27 '18 at 19:01







Data is 30000, so I should use data count. Is there any property of chart to use 1000 points of these 30000 points?

– barteloma
Nov 27 '18 at 19:01















I mean to add less points to the chart if the speed is the problem. For example, adding every 30th point by replacing i++ with i += 30

– Slai
Nov 27 '18 at 19:27





I mean to add less points to the chart if the speed is the problem. For example, adding every 30th point by replacing i++ with i += 30

– Slai
Nov 27 '18 at 19:27













Why do you add so many Series??? That is not what series is made for! 30k points is even a lot but series??? Why would you use more than one series??

– TaW
Nov 27 '18 at 19:56







Why do you add so many Series??? That is not what series is made for! 30k points is even a lot but series??? Why would you use more than one series??

– TaW
Nov 27 '18 at 19:56














1 Answer
1






active

oldest

votes


















1














Try using Chart event.



public partial class Form1 : Form
{
private int _pointsCount;

public Form1()
{
InitializeComponent();
}

private void Draw()
{
_pointsCount = 300000;
var range = Enumerable.Range(0, _pointsCount);
Series series = new Series();

foreach (var i in range)
{
series.Points.Add(new DataPoint(0, i));
}

chart1.PostPaint += OnDrawingFinished;
chart1.Series.Add(series);
}

private void OnDrawingFinished(object sender, ChartPaintEventArgs e)
{
var chart = (Chart)sender;
var points = chart.Series.SelectMany(x => x.Points).Count();

if (points < _pointsCount) return;

MessageBox.Show("Done!");
chart1.PostPaint -= OnDrawingFinished;
}

private void button1_Click(object sender, EventArgs e)
{
Draw();
}
}


Wokrs here for me for first try. Its not so elegant way but still works.






share|improve this answer
























  • Preparing a series before adding it to th chart is probably a good idea. But the main difference is that you inly create one series, not 30k. Also: What do you mean by Chart event ?

    – TaW
    Nov 27 '18 at 19:58











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53506211%2fc-sharp-desktop-chart-draw-complete-takes-long-time%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Try using Chart event.



public partial class Form1 : Form
{
private int _pointsCount;

public Form1()
{
InitializeComponent();
}

private void Draw()
{
_pointsCount = 300000;
var range = Enumerable.Range(0, _pointsCount);
Series series = new Series();

foreach (var i in range)
{
series.Points.Add(new DataPoint(0, i));
}

chart1.PostPaint += OnDrawingFinished;
chart1.Series.Add(series);
}

private void OnDrawingFinished(object sender, ChartPaintEventArgs e)
{
var chart = (Chart)sender;
var points = chart.Series.SelectMany(x => x.Points).Count();

if (points < _pointsCount) return;

MessageBox.Show("Done!");
chart1.PostPaint -= OnDrawingFinished;
}

private void button1_Click(object sender, EventArgs e)
{
Draw();
}
}


Wokrs here for me for first try. Its not so elegant way but still works.






share|improve this answer
























  • Preparing a series before adding it to th chart is probably a good idea. But the main difference is that you inly create one series, not 30k. Also: What do you mean by Chart event ?

    – TaW
    Nov 27 '18 at 19:58
















1














Try using Chart event.



public partial class Form1 : Form
{
private int _pointsCount;

public Form1()
{
InitializeComponent();
}

private void Draw()
{
_pointsCount = 300000;
var range = Enumerable.Range(0, _pointsCount);
Series series = new Series();

foreach (var i in range)
{
series.Points.Add(new DataPoint(0, i));
}

chart1.PostPaint += OnDrawingFinished;
chart1.Series.Add(series);
}

private void OnDrawingFinished(object sender, ChartPaintEventArgs e)
{
var chart = (Chart)sender;
var points = chart.Series.SelectMany(x => x.Points).Count();

if (points < _pointsCount) return;

MessageBox.Show("Done!");
chart1.PostPaint -= OnDrawingFinished;
}

private void button1_Click(object sender, EventArgs e)
{
Draw();
}
}


Wokrs here for me for first try. Its not so elegant way but still works.






share|improve this answer
























  • Preparing a series before adding it to th chart is probably a good idea. But the main difference is that you inly create one series, not 30k. Also: What do you mean by Chart event ?

    – TaW
    Nov 27 '18 at 19:58














1












1








1







Try using Chart event.



public partial class Form1 : Form
{
private int _pointsCount;

public Form1()
{
InitializeComponent();
}

private void Draw()
{
_pointsCount = 300000;
var range = Enumerable.Range(0, _pointsCount);
Series series = new Series();

foreach (var i in range)
{
series.Points.Add(new DataPoint(0, i));
}

chart1.PostPaint += OnDrawingFinished;
chart1.Series.Add(series);
}

private void OnDrawingFinished(object sender, ChartPaintEventArgs e)
{
var chart = (Chart)sender;
var points = chart.Series.SelectMany(x => x.Points).Count();

if (points < _pointsCount) return;

MessageBox.Show("Done!");
chart1.PostPaint -= OnDrawingFinished;
}

private void button1_Click(object sender, EventArgs e)
{
Draw();
}
}


Wokrs here for me for first try. Its not so elegant way but still works.






share|improve this answer













Try using Chart event.



public partial class Form1 : Form
{
private int _pointsCount;

public Form1()
{
InitializeComponent();
}

private void Draw()
{
_pointsCount = 300000;
var range = Enumerable.Range(0, _pointsCount);
Series series = new Series();

foreach (var i in range)
{
series.Points.Add(new DataPoint(0, i));
}

chart1.PostPaint += OnDrawingFinished;
chart1.Series.Add(series);
}

private void OnDrawingFinished(object sender, ChartPaintEventArgs e)
{
var chart = (Chart)sender;
var points = chart.Series.SelectMany(x => x.Points).Count();

if (points < _pointsCount) return;

MessageBox.Show("Done!");
chart1.PostPaint -= OnDrawingFinished;
}

private void button1_Click(object sender, EventArgs e)
{
Draw();
}
}


Wokrs here for me for first try. Its not so elegant way but still works.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 27 '18 at 19:10









miechooymiechooy

1,10341839




1,10341839













  • Preparing a series before adding it to th chart is probably a good idea. But the main difference is that you inly create one series, not 30k. Also: What do you mean by Chart event ?

    – TaW
    Nov 27 '18 at 19:58



















  • Preparing a series before adding it to th chart is probably a good idea. But the main difference is that you inly create one series, not 30k. Also: What do you mean by Chart event ?

    – TaW
    Nov 27 '18 at 19:58

















Preparing a series before adding it to th chart is probably a good idea. But the main difference is that you inly create one series, not 30k. Also: What do you mean by Chart event ?

– TaW
Nov 27 '18 at 19:58





Preparing a series before adding it to th chart is probably a good idea. But the main difference is that you inly create one series, not 30k. Also: What do you mean by Chart event ?

– TaW
Nov 27 '18 at 19:58




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53506211%2fc-sharp-desktop-chart-draw-complete-takes-long-time%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks