1

i want to print a graph into Excel document. I want it:

Graph that I want to print

When I create the graph with code, the result are:

Resulting graph with code

The used code is:

# Add graph.
set chObjs [$worksheet ChartObjects]
set charts [$chObjs Add $graphXpos $graphYpos 400 200] ; # x y width height
wav charts
set chart  [$charts Chart]

set valuesRange [$worksheet Range $firstCellValues $lastCell]; # in this area should be placed values of the graph
# First cell and last cell are the correct rang values.
# Parameters [Source], [Gallery], [Format], [PlotBy], [CategoryLabels], [SeriesLabels], [HasLegend], [Title], [CategoryTitle], [ValueTitle], [ExtraTitle]
$chart ChartWizard $valuesRange 74 3 2 0 0 1 "$graphName" "Minor principal strain (E22)" "Major principal strain (E11)"
braX
  • 11,506
  • 5
  • 20
  • 33

1 Answers1

0

You need to create a "Scatter with Straight Lines"-chart.
Don't know the language you are using in your code, but in VBA it's rather simple:

With ActiveSheet                       ' Use the sheet you need
    Dim sourceRange As Range
    Set sourceRange = .Range("B1:C9")  ' Change to the range with your data 
    Dim ch As Shape
    Set ch = .Shapes.AddChart2(240, xlXYScatterLinesNoMarkers)
    ch.Chart.SetSourceData Source:=sourceRange
End With

(The meaning of the 240 is not really well documented, best I could find was What does the number in the AddChart2 VBA macro represent?)

FunThomas
  • 23,043
  • 3
  • 18
  • 34