2016-03-22 14 views
0

Kodumda grafik oluşturuyorum ve ekranda görüntülüyorsunuz. iyi görünüyor: X ve Y ekseni etiketleri ile güzel bir eğri. Ben bir resim olarak kaydetmek giderkenKaydedilen grafikte görünecek etiketler ve başlık alamıyor (C# .NET, System.Windows.Controls.DataVisualization.Charting)

Chart with axis labels and title visible

Ama, etiketler ve başlık karartılmıştır. İşte grafik için xaml var

Chart with axis labels and title blacked out

...

      <chartingToolkit:Chart Name="chart" Title="Test Results" VerticalAlignment="Top" Height="450" Width="450"> 
          <chartingToolkit:LineSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}" IsSelectionEnabled="True" Title="" Foreground="Black" Background="Blue" BorderBrush="Blue"> 
           <chartingToolkit:LineSeries.DataPointStyle> 
            <Style TargetType="{x:Type chartingToolkit:LineDataPoint}"> 
             <Setter Property="Width" Value="2"/> 
             <Setter Property="Height" Value="2"/> 
            </Style> 
           </chartingToolkit:LineSeries.DataPointStyle> 
          </chartingToolkit:LineSeries> 

          <chartingToolkit:Chart.LegendStyle> 
           <Style TargetType="Control"> 
            <Setter Property="Width" Value="0"/> 
            <Setter Property="Height" Value="0"/> 
           </Style> 
          </chartingToolkit:Chart.LegendStyle> 
         </chartingToolkit:Chart> 

Ve kaydetmek görüntü yöntemi:

private void buttonSaveImage_Click(object sender, RoutedEventArgs e) 
    { 

     double printScale = 96; // pixels per inch 


     // RenderTargetBitmap/Render renders the GUI element in the context of the parent control. 
     // The area of the parent control that is not the desired element is masked in black pixels. 
     // We render the chart inside the area of the parent, then crop the area of the chart from the larger image. 
     renderBitmap = new RenderTargetBitmap((int)chart.ActualWidth, (int)chart.ActualHeight, printScale, printScale, PixelFormats.Default); 


     // store the rendered chart to the bitmap 
     renderBitmap.Render(chart); 

     BitmapEncoder encoder = new JpegBitmapEncoder(); 
     string filename = String.Empty; 
     // pop up save file dialog, get file name & encoder type (jpg, bmp, png, etc.) 
     if (TryGetGraphicFilePath(ref filename, ref encoder)) 
     { 
      encoder.Frames.Add(BitmapFrame.Create(renderBitmap)); 
      FileStream fs = new FileStream(filename, FileMode.Create); 
      encoder.Save(fs); 
      fs.Flush(); 
      fs.Close(); 
     } 
    } 

herhangi bir düşünce?

BTW, kullandığım teknikler benim için yeni; İnce buzda çok uzaktayım. Googling'i denedim, ama boş oluyorum. Herhangi bir yardım için minnettar olurum. Teşekkürler!

cevap

2

Grafik elemanını ızgarada beyaz bir arka planla kaydırmayı deneyin, ardından buttonSaveImage_Daha sonra tablo yerine ızgara oluşturmayı deneyin.

Umut çalışıyor

+0

Kazanan, kazanan, tavuk akşam yemeği! Evet, bu mükemmel bir şekilde çalıştı. Aslında, yalnızca arkaplan = "Beyaz" ifadesini grafik üzerinde kendim denedim ve bu hile yaptı - Grid gerekli! Teşekkürler! –