You are viewing limited content. For full access, please sign in.

Question

Question

How can I create a StackedColumn Chart with multivalues ?

asked on December 11, 2018

Hi all!

 

Using SDK, I would to create a StackedColumn Chart with multi values in the same column ; like this.

 

Actually, I have a SDK to create a Chart with only 1 value by column.

 

I wish to adapt the script but idk how to do.

 

I need your helps please.

 

This is the script.

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports Laserfiche.RepositoryAccess
Imports System.Windows.Forms.DataVisualization.Charting
Imports System.Drawing


Namespace WorkflowActivity.Scripting.ScriptSDKpourgénérerlegraphique2
    '''<summary>
    '''Offre une ou plusieurs méthodes qui peuvent être exécutées au moment de l'exécution de l'activité de scriptage du flux de travail.
    '''</summary>
    Public Class Script1
        Inherits RAScriptClass102
        '''<summary>
        '''Cette méthode est exécutée quand l'activité est effectuée.
        '''</summary>
        Protected Overrides Sub Execute()
            'Rédigez votre code ici. La propriété BoundEntryInfo accèdera à l'entrée, RASession obtiendra la section de Repository Access

            'Get the tokens for values and labels...
            Dim valuesToken as List(Of Object) = Me.GetTokenValue("ChartValues2")
            Dim labelsToken As List(Of Object) = Me.GetTokenValue("ChartLabels2")
            Dim count As Integer = valuesToken.Count-1

            'Convert the multivalue tokens to arrays...
            Dim chartValues(count) As Double
            Dim chartLabels(count) As String

            For i As Integer = 0 to count
                chartValues(i) = CDbl(valuesToken(i))
                chartLabels(i) = labelsToken(i).ToString
            Next

            'Create a new chart...
            Dim chart As Chart = New Chart()
            chart.Width = 700
            chart.Height = 300

            'Add a title to the chart...
            Dim title As New Title(Me.GetTokenValue("ChartTitle2"))
            title.Alignment = ContentAlignment.TopLeft
            title.Font = New Font("Arial", 14, FontStyle.Bold)
            chart.Titles.Add(title)

            'Add the legend for the data...
            Dim legend As New Legend(Me.GetTokenValue("LegendTitle2"))
            chart.Legends.Add(legend)

            'Create a new data series and set the chart type to a StackedColumn chart...
            Dim series As Series = New Series("OI")
            series.ChartType = SeriesChartType.StackedColumn
            series.IsValueShownAsLabel = True
            chart.Series.Add(series)

            'Bind the labels and values as datapoints...
            chart.Series("OI").Points.DataBindXY(chartLabels, chartValues)

            'Create a new chart area and add it to the chart object...
            Dim chartArea As ChartArea = New ChartArea()
            Dim yAxis As Axis = New Axis(chartArea, AxisName.Y)
            Dim xAxis As Axis = New Axis(chartArea, AxisName.X)
            chartArea.AxisX.Interval = 1
            chart.ChartAreas.Add(chartArea)






            'Now write the chart image to the document...
            Using docInfo As DocumentInfo = Me.BoundEntryInfo()

                'Read the chart image into a byte array...
                Dim imageData() As Byte
                Using ms As New System.IO.MemoryStream
                    chart.SaveImage(ms, ChartImageFormat.Tiff)
                    imageData = ms.ToArray
                End Using

                'Lock the document and append a blank page...
                docInfo.Lock(LockType.Exclusive)
                Dim pInfo As PageInfo = docinfo.AppendPage

                'Write the image to the new page...
                Using writer As System.IO.Stream = pInfo.WritePagePart(PagePart.Image, imageData.Length)
                    writer.Write(imageData, 0, imageData.Length)
                End Using

                'Save and unlock the document...
                docInfo.Save()
                docInfo.Unlock()

            End Using
        End Sub
    End Class
End Namespace

 

Thanks in advance.

Regards

 

0 0

Replies

replied on December 11, 2018

What you're asking isn't so much an SDK question as it is a question about the Windows Forms charting libraries.

First, you'll need to make sure that your chart values have the appropriate values. You need to have a data point for each x-value in each series. They need to be ordered with the x-values ascending.

Then you can change the ChartType to StackedColumn100, and that should get you what you want.

It's been forever since I've done anything with WinForms, so I'm a bit fuzzy on the details.

 

2 0
replied on December 12, 2018

Thank you Devin. I found how to do.

This is not perfect because I don't want the value "0" but that answers my question so I'm sharing my solution.

 

 

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports Laserfiche.RepositoryAccess
Imports System.Windows.Forms.DataVisualization.Charting
Imports System.Drawing


Namespace WorkflowActivity.Scripting.ScriptSDKpourgénérerlegraphique3
    '''<summary>
    '''Offre une ou plusieurs méthodes qui peuvent être exécutées au moment de l'exécution de l'activité de scriptage du flux de travail.
    '''</summary>
    Public Class Script1
        Inherits RAScriptClass102
        '''<summary>
        '''Cette méthode est exécutée quand l'activité est effectuée.
        '''</summary>
        Protected Overrides Sub Execute()
            'Rédigez votre code ici. La propriété BoundEntryInfo accèdera à l'entrée, RASession obtiendra la section de Repository Access

            'Get the tokens for values and labels..._______________________________________________________________
            Dim valuesToken1 as List(Of Object) = Me.GetTokenValue("JetonDepannage")
            Dim valuesToken2 as List(Of Object) = Me.GetTokenValue("JetonEntretien")
            Dim valuesToken3 as List(Of Object) = Me.GetTokenValue("JetonInstallationMachine")
            Dim valuesToken4 as List(Of Object) = Me.GetTokenValue("JetonLivraisonConsommable")
            Dim valuesToken5 as List(Of Object) = Me.GetTokenValue("JetonLivraisonCopieur")
            Dim valuesToken6 as List(Of Object) = Me.GetTokenValue("JetonRecupCopieur")
            '______________________________________________________________________________________________________


            Dim labelsToken1 As List(Of Object) = Me.GetTokenValue("ChartLabels1")

            Dim count As Integer = valuesToken1.Count-1


            'Convert the multivalue tokens to arrays...____________________________________________________________
            Dim chartValues1(count) As Double
            Dim chartValues2(count) As Double
            Dim chartValues3(count) As Double
            Dim chartValues4(count) As Double
            Dim chartValues5(count) As Double
            Dim chartValues6(count) As Double
            '______________________________________________________________________________________________________

            Dim chartLabels(count) As String


            For i As Integer = 0 to count
                '______________________________________________________________________________________________________
                If  CDbl(valuesToken1(i)) > 0 Then
                    chartValues1(i) = CDbl(valuesToken1(i))
                    End If
                If  CDbl(valuesToken2(i)) > 0 Then
                    chartValues2(i) = CDbl(valuesToken2(i))
                    End If
                If  CDbl(valuesToken3(i)) > 0 Then
                    chartValues3(i) = CDbl(valuesToken3(i))
                    End If
                If  CDbl(valuesToken4(i)) > 0 Then
                    chartValues4(i) = CDbl(valuesToken4(i))
                    End If
                If  CDbl(valuesToken5(i)) > 0 Then
                    chartValues5(i) = CDbl(valuesToken5(i))
                    End If
                If  CDbl(valuesToken6(i)) > 0 Then
                    chartValues6(i) = CDbl(valuesToken6(i))
                    End If
                '______________________________________________________________________________________________________

                chartLabels(i) = labelsToken1(i).ToString
            Next

            'Create a new chart...
            Dim chart As Chart = New Chart()
            chart.Width = 1024
            chart.Height = 780

            'Add a title to the chart...
            Dim title As New Title(Me.GetTokenValue("ChartTitle2"))
            title.Alignment = ContentAlignment.TopLeft
            title.Font = New Font("Arial", 14, FontStyle.Bold)
            chart.Titles.Add(title)

            'Add the legend for the data...
            Dim legend As New Legend(Me.GetTokenValue("LegendTitle2"))
            chart.Legends.Add(legend)

            'Create a new data series and set the chart type to a StackedColumn chart..._____________________________

            Dim series As Series = New Series("Dépannage")
            series.ChartType = SeriesChartType.StackedColumn
            series.IsValueShownAsLabel = True

            Dim series2 As Series = New Series("Entretien")
            series2.ChartType = SeriesChartType.StackedColumn
            series2.IsValueShownAsLabel = True

            Dim series3 As Series = New Series("Installation Machine")
            series3.ChartType = SeriesChartType.StackedColumn
            series3.IsValueShownAsLabel = True

            Dim series4 As Series = New Series("Livraison Consommables")
            series4.ChartType = SeriesChartType.StackedColumn
            series4.IsValueShownAsLabel = True

            Dim series5 As Series = New Series("Livraison Copieur")
            series5.ChartType = SeriesChartType.StackedColumn
            series5.IsValueShownAsLabel = True

            Dim series6 As Series = New Series("Récup. Copieur")
            series6.ChartType = SeriesChartType.StackedColumn
            series6.IsValueShownAsLabel = True

            '______________________________________________________________________________________________________



            '______________________________________________________________________________________________________
             chart.Series.Add(series)
             chart.Series.Add(series2)
             chart.Series.Add(series3)
             chart.Series.Add(series4)
             chart.Series.Add(series5)
             chart.Series.Add(series6)
            '______________________________________________________________________________________________________



            'Bind the labels and values as datapoints...__________________________________________________________
            chart.Series("Dépannage").Points.DataBindXY(chartLabels, chartValues1)
            chart.Series("Entretien").Points.DataBindY(chartValues2)
            chart.Series("Installation Machine").Points.DataBindY(chartValues3)
            chart.Series("Livraison Consommables").Points.DataBindY(chartValues4)
            chart.Series("Livraison Copieur").Points.DataBindY(chartValues5)
            chart.Series("Récup. Copieur").Points.DataBindY(chartValues6)

            '______________________________________________________________________________________________________


            'Create a new chart area and add it to the chart object...
            Dim chartArea As ChartArea = New ChartArea()
            Dim yAxis As Axis = New Axis(chartArea, AxisName.Y)
            Dim xAxis As Axis = New Axis(chartArea, AxisName.X)
            chartArea.AxisX.Interval = 1
            chart.ChartAreas.Add(chartArea)


            'Now write the chart image to the document...
            Using docInfo As DocumentInfo = Me.BoundEntryInfo()

                'Read the chart image into a byte array...
                Dim imageData() As Byte
                Using ms As New System.IO.MemoryStream
                    chart.SaveImage(ms, ChartImageFormat.Tiff)
                    imageData = ms.ToArray
                End Using

                'Lock the document and append a blank page...
                docInfo.Lock(LockType.Exclusive)
                Dim pInfo As PageInfo = docinfo.AppendPage

                'Write the image to the new page...
                Using writer As System.IO.Stream = pInfo.WritePagePart(PagePart.Image, imageData.Length)
                    writer.Write(imageData, 0, imageData.Length)
                End Using

                'Save and unlock the document...
                docInfo.Save()
                docInfo.Unlock()

            End Using
        End Sub
    End Class
End Namespace

 

 

0 0
replied on December 12, 2018

Looks good!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.