打印图表预览c#

时间:2014-09-24 12:11:29

标签: c# winforms charts

我在win-forms中使用图表,尝试在按钮的点击事件中查看打印预览。试过这个.chart1.Printing.PrintPreview()但是它显示了一个空页面。

这是我的代码

//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();
}

1 个答案:

答案 0 :(得分:2)

试试这个,

PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = this.chart1.PrintDocument;
ppd.ShowDialog();
相关问题