• Resolved tangobango

    (@tangobango)


    Hi. This is a great plugin. I’m using it already for the tables and am just exploring it for the charts.

    I’m trying to explode pie segments. I must have a JSON problem, but I don’t see it. I’ve searched through the help and the forum, but it looks to me like it should work.

    I’m referencing this code from the Google documentation:

     var options = {
              title: 'Indian Language Use',
              legend: 'none',
              pieSliceText: 'label',
              slices: {  4: {offset: 0.2},
                        12: {offset: 0.3},
                        14: {offset: 0.4},
                        15: {offset: 0.5},
              }

    I’m using this gdoc code:
    [gdoc key="https://docs.google.com/spreadsheets/d/1BZsqE-CRGtX2MSDgfzPUWikcVm0PQr8gWgDUrxRDhtw/edit?usp=sharing" chart="Pie" query="select C, D" chart_height=600 chart_width=600 title="My Test Data" chart_slice_visibility_threshold=0.14 chart_pie_slice_text="label" chart_pie_slice_text_style='{"color": "black", "fontSize": 15}' chart_slices='{2:{"offset": 0.2}, 3:{"offset": 0.4}}']

    Here’s my test page:

    https://test.edkatzman.com/index.php/2017/01/13/graph#exploded

    Thanks for any guidance. I think once I get this, I’ll be all set.

    • This topic was modified 7 years, 10 months ago by tangobango.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Meitar

    (@meitar)

    The Google documentation code is not JSON, it’s JavaScript. The two are (confusingly) not syntactically the same. JSON requires double-quotes around both keys and string values. So, for instance:

    title: 'Indian Language Use',
    

    must be changed to

    "title": "Indian Language Use",
    

    and similar, if you’re going to use a JSON object directly (in the settings screen, for instance).

    As for the chart_slices attribute, it doesn’t look like you’ve actually translated the JavaScript to an attribute correctly; the two are simply not the same value at all. Is that intentional?

    Thread Starter tangobango

    (@tangobango)

    Hi. Thanks for the rapid reply.

    I think I’ve got your first point. I believe I used it correctly in my gdoc code as:

    chart_pie_slice_text_style='{"color": "black", "fontSize": 15}'

    My confusion is coming when I have nested levels, in my example the {“offset”: 0.4″} as the value for the key “3” (I’m not sure key: value is the right JSON terminology.)

    (I’m also trying to employ this comment from your docs: “Note that when a JSON object is used as a value, the shortcode attribute’s value must be single-quoted.”

    I’m sorry, but I don’t understand your point “the two are simply not the same value at all. Is that intentional?”

    Could you write the correct attribute value to explode a slice? I think that would help me greatly.

    Thanks.

    • This reply was modified 7 years, 10 months ago by tangobango.
    Plugin Author Meitar

    (@meitar)

    This JavaScript:

    slices: {  4: {offset: 0.2},
                        12: {offset: 0.3},
                        14: {offset: 0.4},
                        15: {offset: 0.5},
    }

    Translated to a shortcode attribute:

    chart_slices='{4 : {"offset": 0.2}, 12: {"offset":0.3}, 14: {"offset": 0.4}, 15: {"offset": 0.5} }'

    Your chart_slices attribute value doesn’t use this value, is all I meant.

    Could you write the correct attribute value to explode a slice? I think that would help me greatly.

    The above is the correct code to use, according to the Google docs.

    Thread Starter tangobango

    (@tangobango)

    Sorry to bother you again — this will be the last time — but I’m still having problems, not with the syntax but with the output, whenever I go beyond one level in the JSON.

    See my test page at https://test.edkatzman.com/index.php/2017/01/13/graph/

    The bottom graph uses this attribute value but doesn’t explode:

    chart_slices='{2:{"offset": 0.2}, 3:{"offset": 0.4}}'

    which seems to be the same as what you wrote, except for the numbers of the slices:

    chart_slices='{4 : {"offset": 0.2}, 12: {"offset":0.3}, 14: {"offset": 0.4}, 15: {"offset": 0.5} }'

    My whole gdoc code is

    [gdoc key="https://docs.google.com/spreadsheets/d/1BZsqE-CRGtX2MSDgfzPUWikcVm0PQr8gWgDUrxRDhtw/edit?usp=sharing" chart="Pie" query="select C, D" chart_height=600 chart_width=600 title="My Test Data" chart_slice_visibility_threshold=0.14 chart_pie_slice_text="label" chart_pie_slice_text_style='{"color": "black", "fontSize": 15}' chart_slices='{2:{"offset": 0.2}, 3:{"offset": 0.4}}']

    Since chart_pie_slice_text_style is working, I think I have the basic idea.

    I’ve tried Firefox and Chrome with the same results. I’m using a completely new WP install, with only your plugin installed.

    Is there maybe some Google Charts problem?

    Thanks.

    Plugin Author Meitar

    (@meitar)

    I thought for a moment that you’re right, deeply-nested JSON objects were not being evaluated correctly (by my plugin), and that the problem is in my code, not your understanding of the syntax. But I think I may have spoke too soon. The example syntax I gave you above, is also wrong, because I made the same mistake you did (it’s an easy mistake to make, not your fault), which is that JSON key names must be double-quoted.

    I said to use:

    chart_slices='{4 : {"offset": 0.2}, 12: {"offset":0.3}, 14: {"offset": 0.4}, 15: {"offset": 0.5} }'

    but I clearly forgot to quote the key names, so this should be:

    chart_slices='{"4" : {"offset": 0.2}, "12": {"offset":0.3}, "14": {"offset": 0.4}, "15": {"offset": 0.5} }'

    Let me try this out myself and take a closer look to make doubly sure. Either way, thanks for pointing this out.

    • This reply was modified 7 years, 10 months ago by Meitar. Reason: Correction
    Plugin Author Meitar

    (@meitar)

    Okay, yeah, I just tried it out and it looks like I just gave you bad advice and failed to notice the lack of doubly-quoted key names in your shortcode.

    This is a really good example for why I need to write a better interface than writing direct JSON in attribute values. Such an interface has been on my to-do list for, like…a year or two now, but this is a donation-based plugin and, well, y’know how it goes. :\

    Thread Starter tangobango

    (@tangobango)

    Yeah, I just tested it and I’m fine.

    I hit you with a small donation earlier, not enough to make a difference, but just to say thanks and quench your thirst.

    I have one more issue, but I’ll start a new thread.

    Thanks again. Very helpful plugin.

    Plugin Author Meitar

    (@meitar)

    I hit you with a small donation earlier, not enough to make a difference, but just to say thanks and quench your thirst.

    Thanks!

    I have one more issue, but I’ll start a new thread.

    Perfect. I appreciate your tidiness.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Trying to Explode Pie Slices’ is closed to new replies.