Position an inset legend at the top-center

时间:2015-05-12 22:21:57

标签: javascript dom d3.js c3

According to the C3 documentation, function get-localgroupmember { [CmdletBinding()] param( [Parameter(Mandatory=$True,HelpMessage="Enter PC")] [ValidateNotNullorEmpty()] [object]$computername = $null ) BEGIN { $newArray = @(); Add-Type -AssemblyName System.DirectoryServices.AccountManagement $ctype = [System.DirectoryServices.AccountManagement.ContextType]::Machine } PROCESS{ foreach ($computer in $computername) { If (Test-Connection -ComputerName $computer.name -Quiet -Count 1) { try { $context = New-Object -TypeName System.DirectoryServices.AccountManagement.PrincipalContext -ArgumentList $ctype, $computer.name $idtype = [System.DirectoryServices.AccountManagement.IdentityType]::SamAccountName $group = [System.DirectoryServices.AccountManagement.GroupPrincipal]::FindByIdentity($context, $idtype, 'Administrators') $group.Members | select @{N='Server'; E={$computer.name}}, @{N='Domain'; E={$_.Context.Name}}, samaccountName $objComputer = [pscustomobject] @{ Server = $computer.name Domain = $group.Members | select @{N='Domain'; E={$_.Context.Name}} Account = $Computer.samaccountName } } catch { $objComputer = [pscustomobject] @{ Server = $computer.name Domain = "Error" Account = "Error" } } } else { $objComputer = [pscustomobject] @{ Server = $computer.name Domain = "Off-Line" Account = "Off-Line" } } $arrayNew += $objComputer } # end foreach } # end PROCESS return $arrayNew } $date = [DateTime]::Today.AddDays(-1) $allComputers = Get-ADComputer -Filter 'PasswordLastSet -ge $date' -properties PasswordLastSet | select Name get-localgroupmember -computername $allComputers | Out-GridView only supports legend.inset.postition, top-left, top-right and bottom-left positions. I would like to have my legend positioned at the bottom-right.

Here is the JS that creates the plot:

top-center

I have attempted to re-position the element after the chart has been rendered via figuring out its current position. However, none of the SVG elements appear to have attributes that enable this kind of introspection:

var chart = c3.generate({
    data: {
        columns: [
            ['data1', 100, 200, 50, 300, 200, 50, 250, 100, 200, 400, 50],
            ['data2', 400, 500, 250, null, 300, 50, 200, 450, 300, 300, 100]
        ],
    },
    legend: {
        position: 'inset',
        inset: {
            anchor: 'top-left', // how do I implement 'top-center'?
            x: 40,
            y: 2,
            step: 1
        }
    }
});

1 个答案:

答案 0 :(得分:3)

您是否只是将插入对象的x值设置为正确的值以使其在顶部居中?

这取决于您的图表是否广泛,以及您的图例有多宽。所以计算结果为(ChartWidth - LegendWidth) / 2

图例对象就像:

legend: {
    position:'inset',
    inset: {
        anchor: 'top-left',
        x: 200 // put the result of your calculation here
    }
}

以下是一个粗略的例子:http://jsfiddle.net/jrdsxvys/11/