Horizontal Bar Chart
-
philipp -
11. Mai 2015 um 21:50 -
Erledigt
-
-
Ist doch aber horizontal, oder ?
-
Da hilft meine ExcelChart UDF (siehe Signatur).
-
Ist doch aber horizontal, oder ?
ja natürlich tut mir leid ich hab es nicht gescheckt:D
Da hilft meine ExcelChart UDF (siehe Signatur).
Hab ich gefunden aber ich kann das script nirgens downloaden.
Phil-IT
-
Ich hab ne Funktion geschrieben, die eine Chart erstellt (Gdi+). Ich geh jetzt erstmal ins Bett. Morgen guck ich mal, dass ich es änder, sodass die Graphic neugezeichnet wird (WM_Paint), wenn es nötig ist.
Außerdem guck ich mal, ob ich das Horizontal auch hinzufüge und ne UDF daraus mache.Kannst ja schonmal ein Beispiel testen: Hab erstmal deine Daten als Beispiel genommen. (Balkenfarbe,etc. füg ich vielleicht auch noch hinzu.
AutoIt
Alles anzeigen#include <GDIplus.au3> #include <GuiConstants.au3> global $ChartArray[0] _GDIPlus_Startup() $hGui=GUICreate("BalkenDiagramm",550,200) GUISetState() global $array=[["voltagedrop [U] Bronze",1.77],["voltagedrop [U] Stahl",2.02]] _showChart($hGui,20,20,484,113,$array,9,1.65,2.05) while Sleep(10) if GUIGetMsg()=-3 then exit endif WEnd ;=============================================================================== ; ; Function Name: _showChart() ; Description: Draws an Chart at an Window ; Parameter(s): $hGui : Handle to the Gui to draw ; $X : X-Position to draw to ; $Y : Y-Position to draw to ; $Width : Width of the Chart ; $Height : Height of the Chart ; $Names : 2D Array. First Entry: Name, Second Entry: Value ; $Entrys : Number of Sections ; $start : Startsection ; $end : EndSection ; Requirement(s): none. ; Return Value(s): ID of Chart ; Author(s): Kanashius ; ;=============================================================================== Func _showChart($hGui,$X,$Y,$Width,$Height,$Names,$Entrys,$start,$end) local $gWidth=WinGetPos($hGui)[2],$gHeight=WinGetPos($hGui)[3] local $graphics = _GDIPlus_GraphicsCreateFromHWND($hGui) local $Abstand=39 local $Balkenbreite=15 $white=_GDIPlus_BrushCreateSolid(0xFFFFFFFF) _GDIPlus_GraphicsFillRect($graphics,$X,$Y,$Width,$Height,$white) ;Zeichne Balkennamen $MaxWidth=0 for $i=0 to UBound($Names)-1 step 1 _GDIPlus_GraphicsDrawString($graphics,$Names[$i][0],$X+5,$Y+5+$Abstand*$i) $MaxSize=_GetTextLabelWidth($Names[$i][0], "Arial", 10) if $MaxWidth<$MaxSize then $MaxWidth=$MaxSize endif next ;Zeichne kleine Balkentrenner $MaxSize+=4 $count=0 for $i=0 to UBound($Names)-1 step 1 _GDIPlus_GraphicsDrawLine($graphics,$X+$MaxSize,$Y+2+$i*$Abstand,$X+$MaxSize+4,$Y+2+$i*$Abstand) $count+=1 Next _GDIPlus_GraphicsDrawLine($graphics,$X+$MaxSize,$Y+2+$count*$Abstand,$X+$Width-20,$Y+2+$count*$Abstand) ;Gebe Breite $luecke=(($Abstand-$Balkenbreite)/2) $MaxNumber=0 for $i=0 to UBound($Names)-1 step 1 $Names[$i][1]-=$start $MaxNumber=$Names[$i][1]>$MaxNumber?$Names[$i][1]:$MaxNumber next ;Zeichne Balken $MaxBalkenSize=($Width-($X+$MaxSize+6))/($end-$start) ;$MaxBalkenSize-=10 for $i=0 to UBound($Names)-1 step 1 if $Names[$i][1]>=0 then $white=_GDIPlus_BrushCreateSolid(0xFF4f81bd) _GDIPlus_GraphicsFillRect($graphics,$X+$MaxSize+6,$Y+$luecke*($i+1)+$luecke*$i+$i*$Balkenbreite,$MaxBalkenSize*$Names[$i][1],$Balkenbreite,$white) endif next ;Zeichne Texte $oneEntry=($end-$start)/$Entrys $oneEntryWidth=($Width-($X+$MaxSize+5))/$Entrys $MaxWidthText=0 for $i=0 to $Entrys Step 1 $MaxSizeTmp=_GetTextLabelWidth(Round($start+$oneEntry*$i,2), "Arial", 10) if $MaxWidthText<$MaxSizeTmp then $MaxWidthText=$MaxSizeTmp endif next $MaxWidthText/=2 for $i=0 to $Entrys Step 1 _GDIPlus_GraphicsDrawString($graphics,Round($start+$oneEntry*$i,2),$X+$MaxSize+5+$oneEntryWidth*$i-$MaxWidthText,$Y+2+$count*$Abstand+4+5) _GDIPlus_GraphicsDrawLine($graphics,$X+$MaxSize+5+$oneEntryWidth*$i,$Y+2,$X+$MaxSize+5+$oneEntryWidth*$i,$Y+2+$count*$Abstand+4) next ;Aktualisiere ChartArray for $i=0 to UBound($ChartArray)-1 step 1 if $ChartArray[$i]="" then $ChartArray[$i]=$graphics return $i EndIf next ReDim $ChartArray[UBound($ChartArray)+1] $ChartArray[UBound($ChartArray)-1]=$graphics return UBound($ChartArray)-1 EndFunc Func _deleteChart($hGui,$Number) ;GUICtrlGetBkColor($hWnd) _WinAPI_RedrawWindow($hGui) _GDIPlus_GraphicsDispose($ChartArray[$Number]) $ChartArray[$Number]="" EndFunc ;Author: b8bboi@www.autoitscript.com Func _GetTextLabelWidth($s_WinText, $s_TextFont, $i_FontSize, $i_FontWeight = -1) Local Const $DEFAULT_CHARSET = 0 ; ANSI character set Local Const $OUT_CHARACTER_PRECIS = 2 Local Const $CLIP_DEFAULT_PRECIS = 0 Local Const $PROOF_QUALITY = 2 Local Const $FIXED_PITCH = 1 Local Const $RGN_XOR = 3 Local Const $LOGPIXELSY = 90 $h_WinTitle = "Get Label Width" If $i_FontWeight = "" Or $i_FontWeight = -1 Then $i_FontWeight = 600 ; default Font weight Local $h_GUI = GUICreate($h_WinTitle, 10, 10, -100, -100, $WS_POPUPWINDOW, $WS_EX_TOOLWINDOW) Local $hDC = DllCall("user32.dll", "int", "GetDC", "hwnd", $h_GUI) Local $intDeviceCap = DllCall("gdi32.dll", "long", "GetDeviceCaps", "int", $hDC[0], "long", $LOGPIXELSY) $intDeviceCap = $intDeviceCap[0] Local $intFontHeight = DllCall("kernel32.dll", "long", "MulDiv", "long", $i_FontSize, "long", $intDeviceCap, "long", 72) $intFontHeight = -$intFontHeight[0] Local $hMyFont = DllCall("gdi32.dll", "hwnd", "CreateFont", "int", $intFontHeight, _ "int", 0, "int", 0, "int", 0, "int", $i_FontWeight, "int", 0, _ "int", 0, "int", 0, "int", $DEFAULT_CHARSET, _ "int", $OUT_CHARACTER_PRECIS, "int", $CLIP_DEFAULT_PRECIS, _ "int", $PROOF_QUALITY, "int", $FIXED_PITCH, "str", $s_TextFont) DllCall("gdi32.dll", "hwnd", "SelectObject", "int", $hDC[0], "hwnd", $hMyFont[0]) Local $res = DllStructCreate("int;int") Local $ret = DllCall("gdi32.dll", "int", "GetTextExtentPoint32", "int", $hDC[0], "str", $s_WinText, "long", StringLen($s_WinText), "ptr", DllStructGetPtr($res)) Local $intLabelWidth = DllStructGetData($res,1) GUIDelete($h_GUI) Return $intLabelWidth EndFunc
MfG Kanashius.
EDIT: Verdammt... übersehen, dass es für Excel sein soll... (sollte besser lesen lernen :D)
Naja. Vielleicht kann es nochmal jemand gebrauchen^^
Ne UDF mach ich vielleicht trotzdem draus -
Für den Download siehe den Link in meiner Signatur.
-
achso sorry water in der mobilen Ansicht sieht man die Signatur nicht! Dankeschön an euch beide, das von water kann ich aber mehr gebrauchen. Nur verstehe ich noch nicht genau wie ich das anwenden muss, kannst du mir da helfen? Wie erstellt man denn einfach eine einfache barchart? Wäre nett wenn du mir einen kleines Skript schreibst.
LG Philipp
-
Schau Dir in der ZIP-Datei mal das Beispiel _XLChart_BarGroupSet.au3 an.
-
Okay nach langer Arbeit und ewigem hin und her hab ich nun ein gutes Ergebnis! danke für die Hilfe!!
Eine kleine Frage bleibt, kann man den Abstand oben (für die Überschrift gedacht) weglassen? ansonsten würde ich das vielleicht mit GDI+ lösen..
*Mit GDI+ gelöst, jetzt die Frage wie ich die Ressourcen wieder schließe, denn bei mir bleibt EXCEL.exe immer geöffnet:DDanke nochmal water für die tolle Unterstützung!
Philipp
-
Wie startest Du Excel. Poste mal den entsprechenden Teil Deines Skriptes.
-
Ich starte excel überhaupt nicht. Es wird nur ein OBJ erstellt:
[autoit]Local $oExcel = ObjCreate("Excel.Application")
[/autoit]und später dann halt der entsprechende XLChart Befehl
-
Genau so wird Excel gestartet.
Poste mal Dein Skript, dann können wir Dir besser helfen. -
Mein Skript:
Spoiler anzeigen
[autoit]
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
#include <ExcelChart.au3>
#include <GDIPlus.au3>
#include <GDIPlusConstants.au3>Main("voltagedrop", "Stahl", "Bronze", "2,02", "1,77")
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
Func Main($Name, $Head1, $Head2, $Value1, $Value2)
Local $oExcel = ObjCreate("Excel.Application")
$oExcel.Visible = 0
$oExcel.WorkBooks.Add
$oExcel.ActiveWorkbook.Sheets(1).Select()
$oExcel.Activesheet.Cells(2, 1).Value = $Head1
$oExcel.Activesheet.Cells(3, 1).Value = $Head2
$oExcel.Activesheet.Cells(2, 2).Value = $Value1
$oExcel.Activesheet.Cells(3, 2).Value = $Value2
$oExcel.ActiveSheet.Name = $NameLocal $asDataRange[3] = [2, "=" & $Name & "!R2C2:R3C2", "=" & $Name & "!R2C3:R3C3"]
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
Local $asDataName[3] = [1, "=" & $Name & "!B1"]
$aoCharts = _XLChart_ChartCreate($oExcel, 1, $xlColumnClustered, "A4:G12", "", "=" & $Name & "!R2C1:R3C1", $asDataRange, $asDataName, False, "", "", "", "")
_XLChart_ChartSet($aoCharts, $xlBarClustered)
_XLChart_BarGroupSet($aoCharts.ChartGroups(1), Default, -50)
_XLChart_ChartExport($aoCharts, @DesktopDir & "\" & $Name & ".png", "PNG")_GDIPlus_Startup()
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
$hImage = _GDIPlus_ImageLoadFromFile(@DesktopDir & "\" & $Name & ".png")
$iX = _GDIPlus_ImageGetWidth($hImage)
$iY = _GDIPlus_ImageGetHeight($hImage)
$hClone = _GDIPlus_BitmapCloneArea($hImage, 8, 51, 545, 122, $GDIP_PXF24RGB)
_GDIPlus_ImageSaveToFile($hClone, @DesktopDir & "\" & $Name & ".jpg")
_GDIPlus_ImageDispose($hClone)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()
FileDelete(@DesktopDir & "\" & $Name & ".png")EndFunc
[/autoit] -
Check function _Excel_Close how to close Excel.
-
_Excel_Close hat nicht funktioniert. Jetzt andere Lösung:
[autoit]
[/autoit]
$oExcel.Application.DisplayAlerts = 0
$oExcel.Quit()Danke für die Hilfe water!
Lg Phil!
-
Ich sehe grade, dass meine Antwort auf Englisch war. ich poste wohl zu viel im anderen Forum
Hauptsache, es funktioniert!