C# desktop chart draw complete takes long time
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
add a comment |
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
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 replacingi++
withi += 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
add a comment |
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
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
c# .net
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 replacingi++
withi += 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
add a comment |
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 replacingi++
withi += 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
add a comment |
1 Answer
1
active
oldest
votes
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.
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 byChart event
?
– TaW
Nov 27 '18 at 19:58
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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 byChart event
?
– TaW
Nov 27 '18 at 19:58
add a comment |
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.
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 byChart event
?
– TaW
Nov 27 '18 at 19:58
add a comment |
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.
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.
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 byChart event
?
– TaW
Nov 27 '18 at 19:58
add a comment |
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 byChart 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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++
withi += 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