2012-03-09 4 views
6

저는 최근에 C#으로 작업하기 시작 했으므로 여러분 모두 내 무지를 변명해야합니다. 난 그냥 윈도우 차트 컨트롤에 대한 질문이 있는데, 내가 좀 바보 같은 문제가 발생했습니다.외관을 엉망으로 만들지 않고 고해상도 차트를 저장하십시오.

저는 몇 가지 데이터를 나타 내기 위해 멋진 모양의 Windows 차트가 포함 된 보고서가있는 프로그램이 있습니다. 그러나 이러한 차트를 다양한 용도로 파일에 저장하는 방법은 다음과 같습니다.

chart2.SaveImage (savefilename, ChartImageFormat.Png);

내 첫 번째 문제는 저장하기 전에 먼저 차트 컨트롤의 크기를 늘리지 않고 이것을 더 높은 해상도로 저장하는 방법을 잘 모르겠다는 사실에 있습니다. 합리적인 품질의 이미지를 갖는 것이 좋을 것입니다.

두 번째 문제는 차트 컨트롤의 크기를 늘릴 때 사용할 수있는 작업 만 레이블이나 텍스트가 아닌 실제 차트의 크기를 늘릴 수있는 것 같습니다. 이 모든 것을 수동으로 바꿀 수 있다면 문제가되지 않을 것입니다. 바 차트에 대해 수행 한 작업이지만 한 줄에 두껍게 만드는 방법을 알 수 없습니다. 원형 차트의 레이블 줄 . 나는 다음과 같은 이미지에에 화살표를 그린 : 차트가 적절한 해상도로 증가 할 때

http://www.bolinger.ca/chart.png

그래서이 줄 인해 적절한 상대 크기로 증가하지 거의 보이지 않습니다. 나는 그것을 바꿀 수있는 방법이 있어야 할 것처럼 느껴지지만 그것이 무엇이 될지 알 수는 없다.

다시 말해서, 내 무지를 용서하십시오. 이 두 가지 문제 중 하나가 해결 될 수 있다면 나는이 파이 차트가보기 흉하게 보인다고 쉽게 알 수 있습니다. 감사!

답변

1

chart2.RenderTransform = new ScaleTransform(10,10)으로 설정하여 저장하십시오. 이것은 또한 당신의 선을 더 커야합니다.

8

양식에 (Visible = false) 숨겨진 차트 개체를 생성/복제합니다. 양식의 상단 및 왼쪽 속성을 설정할 수도 있습니다. 이 컨트롤을 매우 높은 너비 및 높이 (즉, 2100 x 1500)로 설정하십시오 ... 사양에 맞게 채우고 형식을 지정하십시오. 글꼴 크기 등을 늘리십시오. 숨겨진 차트에서 SaveImage() 또는 DrawToBitmap()을 호출하십시오.

이 파일을 저장할 때 본질적으로 대부분의 워드 프로세싱, 데스크탑 pub 예를 들어, 인쇄를 위해 2100 x 1500 @ 300 dpi = 7 "x 5"...

응용 프로그램에서 응용 프로그램의 크기를 축소하거나 인쇄 할 수도 있습니다. 그래서 이미지가 더 선명 해집니다. 크기를 늘리면 이미지가 흐리거나 흐릿 해집니다.

인쇄 또는 저장을위한 .Net 차트 컨트롤에서 고해상도 차트를 얻는 가장 일관된 방법이므로이 기술을 사용해야했습니다. 고전적인 속임수이지만 작동합니다. :) 예를 들어

:

private void cmdHidden_Click(object sender, EventArgs e) { 
    System.Windows.Forms.DataVisualization.Charting.Title chtTitle = 
     new System.Windows.Forms.DataVisualization.Charting.Title(); 
    System.Drawing.Font chtFont = new System.Drawing.Font("Arial", 42); 
    string[] seriesArray = { "A", "B", "C" }; 
    int[] pointsArray = { 1, 7, 4 }; 

    chart1.Visible = false; 
    chart1.Width = 2100; 
    chart1.Height = 1500; 
    chart1.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.Bright; 

    chtTitle.Font = chtFont; 
    chtTitle.Text = "Demographics Comparison"; 
    chart1.Titles.Add(chtTitle); 

    chart1.Series.Clear(); 

    // populate chart  
    for (int i = 0; i < seriesArray.Length; i++) { 
     Series series = chart1.Series.Add(seriesArray[i]); 
     series.Label = seriesArray[i].ToString(); 
     series.Font = new System.Drawing.Font("Arial", 24); 
     series.ShadowOffset = 5; 
     series.Points.Add(pointsArray[i]); 
    } 

    // save from the chart object itself 
    chart1.SaveImage(@"C:\Temp\HiddenChart.png", ChartImageFormat.Png); 

    // save to a bitmap 
    Bitmap bmp = new Bitmap(2100, 1500); 
    chart1.DrawToBitmap(bmp, new Rectangle(0, 0, 2100, 1500)); 
    bmp.Save(@"C:\Temp\HiddenChart2.png"); 
} 
1

는 여기에 내가, 저장, 더 큰 그래프를 만들어 다음 그래프를 복원하기 위해 만든 클래스입니다. 제 목적을 위해 잘 작동합니다.

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using OfficeOpenXml.Drawing; 
using OfficeOpenXml.Drawing.Chart; 
using System.Drawing.Imaging; 
using System.Windows.Forms.DataVisualization.Charting; 
using System.Windows.Forms; 

namespace Simple_Grapher 
{ 
    class saveQualityChartImage 
    { 
     Chart theChart; 
     System.Drawing.Font oldFont1 = new System.Drawing.Font("Trebuchet MS", 35F, System.Drawing.FontStyle.Bold); 
     System.Drawing.Font oldFont2 = new System.Drawing.Font("Trebuchet MS", 15F, System.Drawing.FontStyle.Bold); 
     System.Drawing.Font oldFont3 = new System.Drawing.Font("Trebuchet MS", 35F, System.Drawing.FontStyle.Bold); 
     System.Drawing.Font oldLegendFont = new System.Drawing.Font("Trebuchet MS", 35F, System.Drawing.FontStyle.Bold); 

     int oldLineWidth1; 
     int oldLineWidth2; 
     int oldLineWidth3; 
     int oldLineWidth4; 

     int oldWidth; 
     int oldHeight; 
     public saveQualityChartImage(Chart inputChart) 
     { 
      if (!(inputChart.Series.Count > 0)) 
      { 
       return; 
      } 
      theChart = inputChart; 
      if (inputChart.Titles.Count > 0) 
      { 
       oldFont1 = inputChart.Titles[0].Font; 
      } 
      oldFont2 = inputChart.ChartAreas[0].AxisX.LabelStyle.Font; 
      oldFont3 = inputChart.ChartAreas[0].AxisX.TitleFont; 
      if (theChart.Legends.Count > 0) 
      { 
       oldLegendFont = theChart.Legends["Legend"].Font; 
      } 
      oldLineWidth1 = theChart.ChartAreas[0].AxisX.LineWidth; 
      oldLineWidth2 = theChart.ChartAreas[0].AxisX.MajorTickMark.LineWidth; 
      oldLineWidth3 = theChart.Series[0].BorderWidth; 
      oldLineWidth4 = theChart.ChartAreas[0].AxisY.MajorGrid.LineWidth; 
      oldWidth = theChart.Width; 
      oldHeight = theChart.Height; 

      saveimage(); 
     } 

     public void saveimage() 
     { 
      theChart.Visible = false; 
      System.Drawing.Font chtFont = new System.Drawing.Font("Trebuchet MS", 35F, System.Drawing.FontStyle.Bold); 
      System.Drawing.Font smallFont = new System.Drawing.Font("Trebuchet MS", 15F, System.Drawing.FontStyle.Bold); 
      if (theChart.Titles.Count > 0) 
      { 
       theChart.Titles[0].Font = chtFont; 
      } 

      theChart.ChartAreas[0].AxisX.TitleFont = chtFont; 
      theChart.ChartAreas[0].AxisX.LineWidth = 3; 
      theChart.ChartAreas[0].AxisX.MajorGrid.LineWidth = 3; 
      theChart.ChartAreas[0].AxisX.LabelStyle.Font = smallFont; 
      theChart.ChartAreas[0].AxisX.MajorTickMark.LineWidth = 3; 

      theChart.ChartAreas[0].AxisY.TitleFont = chtFont; 
      theChart.ChartAreas[0].AxisY.LineWidth = 3; 
      theChart.ChartAreas[0].AxisY.MajorGrid.LineWidth = 3; 
      theChart.ChartAreas[0].AxisY.LabelStyle.Font = smallFont; 
      theChart.ChartAreas[0].AxisY.MajorTickMark.LineWidth = 3; 
      if (theChart.Legends.Count > 0) 
      { 
       theChart.Legends["Legend"].Font = smallFont; 
      } 


      foreach (Series series in theChart.Series) 
      { 
       series.BorderWidth = 3; 

      } 

      theChart.Width = 1800; 
      theChart.Height = 1200; 

      SaveFileDialog save = new SaveFileDialog(); 
      save.DefaultExt = ".png"; 
      if (save.ShowDialog() == DialogResult.OK) 
      { 
       theChart.SaveImage(save.FileName, ChartImageFormat.Png); 
      } 
      resetOldValues(); 

     } 

     private void resetOldValues() 
     { 
      if (theChart.Titles.Count > 0) 
      { 
       theChart.Titles[0].Font = oldFont1; 
      } 

      theChart.ChartAreas[0].AxisX.TitleFont = oldFont3; 
      theChart.ChartAreas[0].AxisX.LineWidth = oldLineWidth1; 
      theChart.ChartAreas[0].AxisX.MajorGrid.LineWidth = oldLineWidth4; 
      theChart.ChartAreas[0].AxisX.LabelStyle.Font = oldFont2; 
      theChart.ChartAreas[0].AxisX.MajorTickMark.LineWidth = oldLineWidth2; 

      theChart.ChartAreas[0].AxisY.TitleFont = oldFont3; 
      theChart.ChartAreas[0].AxisY.LineWidth = oldLineWidth1; 
      theChart.ChartAreas[0].AxisY.MajorGrid.LineWidth = oldLineWidth4; 
      theChart.ChartAreas[0].AxisY.LabelStyle.Font = oldFont2; 
      theChart.ChartAreas[0].AxisY.MajorTickMark.LineWidth = oldLineWidth2; 
      if (theChart.Legends.Count > 0) 
      { 
       theChart.Legends["Legend"].Font = oldLegendFont; 
      } 



      foreach (Series series in theChart.Series) 
      { 
       series.BorderWidth = oldLineWidth3; 

      } 

      theChart.Width = oldWidth; 
      theChart.Height = oldHeight; 
      theChart.Visible = true; 
     } 
    } 
} 
관련 문제