Jagan
Jagan

Reputation: 79

Print Preview of a Chart c#

I'm using a chart in win-forms, trying to see the print preview on a button's click event. Tried this.chart1.Printing.PrintPreview() but it shows an empty page.

Here is my code

//at form load
{
    if (objMaster == null) objMaster = new MasterEstimateSales();
    dt = new DataTable();
    dt = objMaster.ESChart(); 
    chart1.DataSource = dt;
    var series = new Series();
    series.Name = "Sale";
    series.ChartType = SeriesChartType.Bar;
    chart1.Series.Add(series);
    chart1.Series["Sale"].XValueMember = "Variety";
    chart1.Series["Sale"].YValueMembers = "Quantity";
    chart1.ChartAreas[0].AxisY.ScaleBreakStyle.Enabled = true;
    series.IsValueShownAsLabel = true;
    chart1.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0;
    chart1.ChartAreas[0].AxisY.MajorGrid.LineWidth = 0;
    chart1.ChartAreas[0].AxisX.Interval = 1;
    chart1.ChartAreas[0].AxisX.LabelStyle.Font= new System.Drawing.Font("AParanarTSC", 9F, System.Drawing.FontStyle.Regular);

}
// Button Event
private void button1_Click(object sender, EventArgs e)
{
    this.chart1.Printing.PrintPreview();
}

Upvotes: 2

Views: 3158

Answers (1)

Learner
Learner

Reputation: 353

Try this,

PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = this.chart1.PrintDocument;
ppd.ShowDialog();

Upvotes: 3

Related Questions