Assigns the last value set to every chart label

162
April 27, 2017, at 8:56 PM

I created a field in a shortcode to set a footer label for highcarts. I got it to save the value set, it groups it with the chart id in the array and i managed to pass the string from the php file to the js function where it adds the footer label for the chart. But it always assign the last caption i set for a graph in a post to all the other graphs in that post. It probably is something very simple but im stuck in this part. This is the php code:

        $fields = array(
        array(
            'label' => esc_html( 'Graph' ),
            'description' => esc_html( 'Choose the graph' ),
            'attr'    => 'chart',
            'type'    => 'select',
            'options' => $charts,
        ),
        array(
            'label' => esc_html( 'Footer label' ),
            'description' => esc_html( 'Choose the footer label' ),
            'attr' => 'footer_caption',
            'type' => 'text',
        ),
    );
public static function shortcode_ui_chart( $attr, $content, $shortcode_tag ) {
        $attr = shortcode_atts( array(
            'chart' => null,
            'footer_caption' => null,
        ), $attr, $shortcode_tag );

This is how i pass the value of the field to the js file:

<script>
  var captionLabel = "<?php echo $attr['footer_caption']; ?>";
</script>

And this is the js file where i add the footer label:

    Highcharts.setOptions({
  credits: {
          enabled: false
  },
  chart: {
          type: 'column',
          events: {
              load: function () {
                var label = this.renderer.label(captionLabel)
                  .css({
                      width: '400px',
                      fontSize: '9px'
                  })
                  .attr({
                      'r': 2,
                      'padding': 5
                  })
                  .add();
                  label.align(Highcharts.extend(label.getBBox(), {
                      align: 'center',
                      x: 20, // offset
                      verticalAlign: 'bottom',
                      y: 0 // offset
                  }), null, 'spacingBox');
              }
          },
          marginBottom: 120
      }

This is what i get when i print_r $attr (just an example from 1 graph):

 [27-Apr-2017 11:03:27 UTC] Array
(
    [chart] => 23
    [footer_caption] => just another test...
)

The problem is that if i add a caption to the last graph of a post all the other graphs in that post get that caption and not their specific caption and i can see in the db that they are correctly assigned like this:

[the_chart chart="23" footer_caption="just another test..."/]
[the_chart chart="22" footer_caption="teste"/]
[the_chart chart="24" footer_caption="another test..."/]

So can someone tell me how i get it to assign the specific footer label to the right chart and not the last one that i set assigned to every other chart? I'm sorry if its not clear enough or a stupid question.

READ ALSO
in laravel soap give me wrong version error once in a while?

in laravel soap give me wrong version error once in a while?

I try to use soap and connect to wsdl fileI don't know why 2 from 10 request send but other give me wrong version error

372
What order are andWhere(), orWhere(), where() methods evaluated in CakePHP 3?

What order are andWhere(), orWhere(), where() methods evaluated in CakePHP 3?

I'm confused as to something I've read on the CakePHP 3 documentation Query Builder's Advanced Conditions: https://bookcakephp

183
CakePHP 3.x | Cookies reading from subdomain

CakePHP 3.x | Cookies reading from subdomain

I'm having problem when reading cookies on subdomain, which has been written on main one

163
php pdo execute multiple query in loop [duplicate]

php pdo execute multiple query in loop [duplicate]

This question already has an answer here:

202