winform中chart图表的打印示例,如何显示预览,纸张设置等

winform中chart图表的打印示例,如何显示预览,纸张设置等,第1张

帮你看了下,winform 中的chart好像没有打印方法。但有导出生成的方法,可以先生成后在打印

chart1SaveImage("d:\\ddBmp", SystemDrawingImagingImageFormatBmp);

你自己弄个路径,先生成的bmp,然后就用winfrom 的那些打印控件就行pageSetupDialog,printDocument,printPreviewDialog,printDialog

pageSetupDialog和printPreviewDialog的Docuent属性设置为printDocument,然后在printDocument的printpage方法中写

Bitmap bitmap = new Bitmap("d:\\ddBmp");

eGraphicsDrawImage(bitmap, eMarginBoundsLeft, eMarginBoundsTop);就行了

预览是thisprintPreviewDialog1ShowDialog(); ,打印是thisprintDocument1Print();,打印设置thispageSetupDialog1ShowDialog();

其实就是把那个chart图表生成的打印出来,关闭窗体时在给生成那个删了,如果怕生成的文件重名就用全局唯一标识

cCharTemp=getchar();主要是接受scanf("%c",&cCharPut);这里按的回车,执行程序时,你输入a,然后回车,实际上缓冲区接受的是两个字符,第一个是'a'第二个是‘\n',scanf("%c",&cCharPut);只把a从缓冲区中取走,但是'\n'还在缓冲区。如果没有getchar这个语句,那么下面的语句scanf("%c",&cCharPut);就会直接读取缓冲区中的'\n‘而不会等到你再去输入字符。而getchar是取走缓冲区中一个字符,把回车给取走,缓冲区空了,你才能再次输入

这个是要设置y轴的值,如果你的数据都是140000以上 那么你可以把y轴的最小值设置成140000

private void SetAxisY()

{

Axis AxisY = new Axis()

{

LineColor = ColorFromArgb(64, 64, 64, 64),

// Y轴标签字体大小

LabelAutoFitMinFontSize = 10,

// Y轴标签显示样式

LabelStyle = new LabelStyle() { Format = "{#}0%" },

// 网格Y轴设置

MajorGrid = new Grid() { LineColor = ColorFromArgb(64, 64, 64, 64) },

// Y轴的最大值

Maximum = 1000,

// Y轴的最小值

Minimum = 0,

// Y轴标签间距

Interval = 500,

// 最小刻度

MajorTickMark = new TickMark() { TickMarkStyle = TickMarkStyleOutsideArea, Size = 500 },

};

SystemWindowsFormsDataVisualizationChartingChart c = new SystemWindowsFormsDataVisualizationChartingChart();

cChartAreas[0]AxisY = AxisY;

}

using System;

using SystemCollectionsGeneric;

using SystemComponentModel;

using SystemData;

using SystemDrawing;

using SystemLinq;

using SystemText;

using SystemWindowsForms;

using SystemWindowsFormsDataVisualizationCharting;

namespace 人体节律

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

曲线(生日Value);

}

private void 三曲线(DateTime 生日)

{

//曲线显示ChartAreasClear();

//曲线显示ChartAreasAdd("Default");

曲线显示ChartAreas["Default"]AxisXLabelStyleInterval = 1;

//曲线显示ChartAreas["Default"]AxisXLabelStyleFormat = "####";

曲线显示ChartAreas["Default"]AxisXMajorGridInterval = 1;

曲线显示ChartAreas["Default"]AxisYMajorGridInterval = 01;//Y轴间隔

曲线显示ChartAreas["Default"]AxisYLabelStyleInterval = 01;//Y轴标注

//曲线显示ChartAreas["Default"]Area3DStyleEnable3D = true;

//曲线显示ChartAreas["Default"]AxisXMinorGridInterval = 1;

//曲线显示ChartAreas["Default"]AxisXMinorTickMarkInterval = 1;

//曲线显示ChartAreas["Default"]AxisXMajorTickMarkInterval = 1;

//曲线显示ChartAreas["Default"]AxisYMinorGridInterval = 01;

//------------------------------------

DateTime 当前日期 = SystemDateTimeNow;

DateTime 假定日期 = ConvertToDateTime("1900-1-1");

if (生日 != 当前日期) { 假定日期 = 生日; }

SystemTimeSpan 日差值 = 当前日期 - 假定日期;

int 间隔 = 日差值Days, 智力 = 间隔 % 33, 情绪 = 间隔 % 28, 体力 = 间隔 % 23; double 均值 = (智力 + 情绪 + 体力) / 3;

曲线显示Series["智力"]PointsClear(); 曲线显示Series["情绪"]PointsClear(); 曲线显示Series["体力"]PointsClear(); 曲线显示Series["均值"]PointsClear();

for (double t = 0; t <= 2 165; t++)//画多长的曲线 t <= 数值可调整如等于33则显示完整的33一个正弦波形

{

double ch1 = MathSin((t + 智力) 2 MathPI / 33);//2MathPIr一个圆周按R的步进增长乘以正弦函数得到点坐标形成以时间为X轴展开的正弦波形/一个周期画多少个点(周期)

曲线显示Series["智力"]PointsAddXY(t, ch1);

double ch2 = MathSin((t + 情绪) 2 MathPI / 28);

曲线显示Series["情绪"]PointsAddXY(t, ch2);

double ch3 = MathSin((t + 体力) 2 MathPI / 23);

曲线显示Series["体力"]PointsAddXY(t, ch3);

double ch4 = 01 MathSin((t + 均值) 2 MathPI / 23);

曲线显示Series["均值"]PointsAddXY(t, ch4);

}

}

private void Form1_Paint(object sender, PaintEventArgs e)

{

画网格();

}

private void 画网格()

{

int 小时 = DateTimeNowHour;

int 秒 = DateTimeNowSecond;

int 分钟 = DateTimeNowMinute;

//Graphics 实例 = 曲线显示CreateGraphics();

Graphics 实例 = thisCreateGraphics();

//实例Clear(ColorWhite);

Pen 线条 = new Pen(ColorGreen, 1);

Pen 线条1 = new Pen(ColorOrange, 1);

for (int 线 = 10; 线 < 210; 线 = 线 + 10)

{

实例DrawLine(线条, new Point(线 + 30, 10), new Point(线 + 30, 200));//竖线需X坐标=同

实例DrawLine(线条1, new Point(40, 线), new Point(230, 线));//横线需Y坐标=同

}

string[] 标注 = { "100", "90", "80", "70", "60", "50", "40", "30", "20", "10", "0", "-10", "-20", "-30", "-40", "-50", "-60", "-70", "-80", "-90", "-100" };

int y = 0; Font font = new SystemDrawingFont("Arial", 9, FontStyleRegular);

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

{ 实例DrawString(标注[i]ToString(), font, BrushesRed, 0, y); y = y + 10; }

PointF[] 弦线值 = new PointF[200], 弦线值1 = new PointF[180];

for (int i = 0; i < 弦线值Length; i++)

{

弦线值[i]X = 40 + i;//起始位置

弦线值[i]Y = 220 / 2 (1 - (float)08 (float)MathSin(i 2 MathPI / 33));

}// 轴位置 幅度

for (int i = 0; i < 弦线值1Length; i++)

{

弦线值1[i]X = 40 + i;//起始位置

弦线值1[i]Y = 220 / 2 (1 - (float)08 (float)MathSin(i 2 MathPI / 28));

}

实例DrawLines(new Pen(SystemColorsWindowText), 弦线值);

实例DrawLines(new Pen(SystemColorsWindowText), 弦线值1);

}

private void 生日_ValueChanged(object sender, EventArgs e)

{

三曲线(生日Value);

}

private void button1_Click(object sender, EventArgs e)

{

//三曲线(生日Value);

}

private void 曲线显示_Paint(object sender, PaintEventArgs e)

{

//三曲线(生日Value);

}

}

}

[csharp] view plain copy print

//

// 曲线显示

//

this

曲线显示Anchor = ((SystemWindowsFormsAnchorStyles)

((((SystemWindowsFormsAnchorStylesTop | SystemWindowsFormsAnchorStylesBottom)

| SystemWindowsFormsAnchorStylesLeft)

| SystemWindowsFormsAnchorStylesRight)));

chartArea1AxisXIsMarginVisible = false;

chartArea1AxisXScaleBreakStyleMaxNumberOfBreaks = 1;

chartArea1AxisXScaleBreakStyleSpacing = 1D;

chartArea1AxisYIsMarginVisible = false;

chartArea1IsSameFontSizeForAllAxes = true;

chartArea1Name = "Default";

this曲线显示ChartAreasAdd(chartArea1);

legend1Name = "Legend1";

this曲线显示LegendsAdd(legend1);

this曲线显示Location = new SystemDrawingPoint(2, 3);

this曲线显示Name = "曲线显示";

series1ChartArea = "Default";

series1ChartType = SystemWindowsFormsDataVisualizationChartingSeriesChartTypeSpline;

series1IsXValueIndexed = true;

series1Legend = "Legend1";

series1Name = "智力";

series2ChartArea = "Default";

series2ChartType = SystemWindowsFormsDataVisualizationChartingSeriesChartTypeSpline;

series2IsXValueIndexed = true;

series2Legend = "Legend1";

series2Name = "情绪";

series3ChartArea = "Default";

series3ChartType = SystemWindowsFormsDataVisualizationChartingSeriesChartTypeSpline;

series3IsXValueIndexed = true;

series3Legend = "Legend1";

series3MarkerSize = 1;

series3Name = "体力";

series4ChartArea = "Default";

series4ChartType = SystemWindowsFormsDataVisualizationChartingSeriesChartTypeSpline;

series4IsXValueIndexed = true;

series4Legend = "Legend1";

series4Name = "均值";

this曲线显示SeriesAdd(series1);

this曲线显示SeriesAdd(series2);

this曲线显示SeriesAdd(series3);

this曲线显示SeriesAdd(series4);

this曲线显示Size = new SystemDrawingSize(780, 186);

this曲线显示TabIndex = 0;

this曲线显示Text = "曲线";

this曲线显示Paint += new SystemWindowsFormsPaintEventHandler(this曲线显示_Paint);

以上就是关于winform中chart图表的打印示例,如何显示预览,纸张设置等全部的内容,包括:winform中chart图表的打印示例,如何显示预览,纸张设置等、c语言中用getchar()接收回车、VS2010 C#用chart导入数据后曲线变化不明显等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9620344.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-30
下一篇 2023-04-30

发表评论

登录后才能评论

评论列表(0条)

保存