PSWriteHTML icon indicating copy to clipboard operation
PSWriteHTML copied to clipboard

Change the colour in a chart

Open Nyfanwy opened this issue 6 years ago • 4 comments

I've noticed while we can change the background colour of a panel, we cannot change the colour of the text that's in a chart in that panel.

Not sure if you can add background colour / text colour to the charts or if text color can be added to the Panel and that shows in the chart?

Cheers!

Nyfanwy avatar Jun 26 '19 16:06 Nyfanwy

Currently, a limited option would be to use New-ChartAxisY for line charts. It has title text colors and so on.

Otherwise, New-ChartTitle would need to be implemented based on https://apexcharts.com/docs/options/title/

title: {
    text: undefined,
    align: 'left',
    margin: 10,
    offsetX: 0,
    offsetY: 0,
    floating: false,
    style: {
      fontSize:  '16px'
      color:  '#263238'
    },
}

If you feel you're up to the task you would need to follow similar pattern done with New-ChartAxisY (so defining it - as [PSCustomObject] and then you would need to follow a trail of what happens till the point where New-ChartInternalAxisY is used to generate JSON.

3 steps are needed:

  1. Create new public function New-ChartTitle - this is simple [pscustomobject] returned from a function
  2. Create new private function New-ChartInternalTitle - this just builds a version of hashtable
  3. Finally modification to New-HTMLTable adding one of those
    if ($HTML) {
        [Array] $Output = & $HTML

        if ($Output.Count -gt 0) {
            foreach ($Parameters in $Output) {
                if ($Parameters.Type -eq 'TableButtonPDF') {
                    $CustomButtons.Add($Parameters.Output)
                } elseif ($Parameters.Type -eq 'TableButtonCSV') {
                    $CustomButtons.Add($Parameters.Output)
                } elseif ($Parameters.Type -eq 'TableButtonPageLength') {
                    $CustomButtons.Add($Parameters.Output)
                } elseif ($Parameters.Type -eq 'TableButtonExcel') {
                    $CustomButtons.Add($Parameters.Output)
                } elseif ($Parameters.Type -eq 'TableButtonPDF') {
                    $CustomButtons.Add($Parameters.Output)
                } elseif ($Parameters.Type -eq 'TableButtonPrint') {
                    $CustomButtons.Add($Parameters.Output)
                } elseif ($Parameters.Type -eq 'TableButtonCopy') {
                    $CustomButtons.Add($Parameters.Output)
                } elseif ($Parameters.Type -eq 'TableCondition') {
                    $ConditionalFormatting.Add($Parameters.Output)
                } elseif ($Parameters.Type -eq 'TableHeaderRow') {
                    $HeaderRows.Add($Parameters.Output)
                }
            }
        }
    }
  1. Finally making sure New-ChartInternalTitle is executed with parameters from point 3.

That's about it :) At least for title options.

PrzemyslawKlys avatar Jun 26 '19 16:06 PrzemyslawKlys

Hi sir ! First of all, you made a great job, it's really good ! Quick and easy to use, very impressive. I'm working with your module Dashimo for few days now, after discovering PSWriteHTML (not sure to understand all differences between the both modules)

As my question is related to colour and charts too, I used the same thread than Nyfanwy. I was asking if it's possible to change the colour of the bar itself. From what I see, it's default colour for every charts, blue > green > yellow > red > purple etc...I would like to be able to change colour for each chartbar. Is this something already possible with your tool ? Is this something you plan to implement ?

Disthene avatar Jun 27 '19 09:06 Disthene

PSWriteHTML has all the code that is responsible for creating HTML. Dashimo is more of a concept, naming scheme that is easy for me to work with. If you're using Dashimo you're basically using PSWriteHTML beneath it.

I thought I added colors for bars, but I did that only for Line Charts. I need to fix that mistake. It's planned. I'll what I can do. Just so you know I only add support to 147 colors (defined names) for now. Maybe, later on, I will let people define custom colors from RGB pallette but I want PSWriteHTML to be user-friendly.

PrzemyslawKlys avatar Jun 27 '19 09:06 PrzemyslawKlys

In fact I just found that" ChartLegend -Color" was doing what I wanted ;) It's perfect ! Keep it up !

Disthene avatar Jun 27 '19 11:06 Disthene