2016-03-22 76 views
0

コード内にグラフを生成して画面に表示していますXとY軸のラベル付きの素敵なカーブです。保存されたグラフにラベルとタイトルが表示されない(C#.NET、System.Windows.Controls.DataVisualization.Charting)

Chart with axis labels and title visible

しかし、私は画像として保存する行くとき、ラベルとタイトルがブラックアウトされています。ここでは、グラフのXAMLです

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> 

て保存画像法:

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

任意の考え?

ところで、私が使っている技術は私には新しいものです。私は薄い氷の上にかなり遠いです。私はグーグルで試してみましたが、空になっています。私は確かにどんな助けにも感謝します。ありがとう!

答えて

2

グラフの要素を白い背景でラップし、buttonSaveImage_Clickでグラフの代わりにグリッドを描画してみます。

ご希望の場合

+0

当選者、勝者、鶏の夕食!はい、これは完全に機能しました。 実際、Background = "White"をチャート自体に指定しようとしましたが、それはトリックを行いました - グリッドは必要ありません!ありがとう! –

関連する問題