Want to apply pattern in pie chart using highchart vuejs
Tried using in data field but nothing worked
color: 'url(#highcharts-default-pattern-0)'
EXPECTED PATTERN:
Highcharts patterns work in the same way in Vue as in pure JS. You need to only:
Load and initialize pattern-fill module:
import Highcharts from 'highcharts';
import patternFillInit from 'highcharts/modules/pattern-fill';
patternFillInit(Highcharts);
Use one of the ways of defining patterns from docs, for example by using patternIndex property:
series: [
{
...,
data: [
{
y: 1,
color: {
patternIndex: 0
},
},
...
]
}
]
Live demo: https://codesandbox.io/s/highcharts-vue-demo-1-5039z3
Docs:
https://www.highcharts.com/docs/chart-design-and-style/pattern-fills
https://github.com/highcharts/highcharts-vue#importing-highcharts-modules
Related
I'm struggling to change the font on a plot produced using chartkick.
I have set up chartkick for Rails 7 using ImportMap.
config/importmap.rb
pin "chartkick", to: "chartkick.js"
pin "Chart.bundle", to: "Chart.bundle.js"
app/javascript/application.js
import "chartkick"
import "Chart.bundle"
I've produced the plot I want using the following code:
<%= line_chart [
{ name: "Apples", data: FruitCount.pluck(:date, :apples) },
{ name: "Pears", data: FruitCount.pluck(:date, :pears) },
{ name: "Oranges", data: FruitCount.pluck(:date, :oranges) },
] %>
I can format the code using the options built into Chartkick (xtitle: "Date", ytitle: "Count", legend: "right" etc) but I'm unable to pass options to chart.js using library (say library: {backgroundColor: "#eee"}). No options are passed and the plot remains with the default formatting.
Has anyone else had similar problems? I just want to change the font of the axis ticks and legend items.
All help greatly appreciated.
I am using both vue single-file components and separating of markup and logic to .pug and .ts files respectively. If you interesting why I don't unify is please see the comments section.
Problem
import template from "#UI_Framework/Components/Controls/InputFields/InputField.vue.pug";
import { Component, Vue } from "vue-property-decorator";
console.log(template);
#Component({
template,
components: {
CompoundControlBase
}
})
export default class InputField extends Vue {
// ...
}
In development building mode exported template is correct (I beautified it for readability):
<CompoundControlBase
:required="required"
:displayInputIsRequiredBadge="displayInputIsRequiredBadge"
<TextareaAutosize
v-if="multiline"
:value="value"
/><TextareaAutosize>
</CompoundControlBase>
In production mode, my markup has been lowercased. So, the console.log(template) outputs:
<compoundcontrolbase
:required=required
:displayinputisrequiredbadge=displayInputIsRequiredBadge
<textareaautosize
v-if=multiline
:value=value
></textareaautosize>
</compoundcontrolbase>
Off course, I got broken view.
Webpack config
const WebpackConfig = {
// ...
optimization: {
noEmitOnErrors: !isDevelopmentBuildingMode,
minimize: !isDevelopmentBuildingMode
},
module: {
rules: [
{
test: /\.vue$/u,
loader: "vue-loader"
},
{
test: /\.pug$/u,
oneOf: [
// for ".vue" files
{
resourceQuery: /^\?vue/u,
use: [ "pug-plain-loader" ]
},
// for ".pug" files
{
use: [ "html-loader", "pug-html-loader" ]
}
]
},
// ...
]
}
}
Comments
To be honest, I don't know why we need ? in resourceQuery: /^\?vue/u, (explanations are welcome).
However, in development building mode above config works property for both xxxx.vue and xxxx.vue.pug files.
I am using below files naming convention:
xxx.pug: pug file which will not be used as vue component template.
xxx.vue.pug: pug file which will be used as vue component template.
xxx.vue: single-file vue component.
xxx.vue.ts: the logic of vue component. Required exported template from xxx.vue.pug as in InputField case.
Why I need xxx.vue.ts? Because of this:
declare module "*.vue" {
import Vue from "vue";
export default Vue;
}
Neither public methods/fields nor non-default methods are visible for TypeScrpt xxx.vue files. For the common (non-applied) components, I can't accept it.
Repro
🌎 GitHub
Step 1: Install dependencies
npm i
Step 2: Let's check the development building first
npm run DevelopmentBuild
In line 156 of DevelopmentBuild\EntryPoint.js, you can check that below pug template:
Alpha
Bravo OK
has been compiled properly:
Step 3: Problem on production build
npm run ProuductionBuild
You can find the lowercased tags in the column 13:
You can also open index.html in your browser and check the console.log() output with compiled TestComponent.
The problem is the "html-loader". It has the option minimize set to true in production mode (html-loader/#minimize).
I had a similar problem in angular and had to unset some options like (see for reference html-minifier-terser#options-quick-reference).
// webpack.config.js
{
test: /\.pug$/u,
oneOf: [
// for ".vue" files
{
resourceQuery: /^\?vue/u,
use: [ "pug-plain-loader" ]
},
// for ".pug" files
{
use: [ "html-loader", "pug-html-loader" ]
}
],
options: {
minimize: { // <----
caseSensitive: false // <----
} // <----
}
},
I have some XML that I want to transform into a Map. I used the middle way of transforming XML to JSON and then greating a map of the json:
import org.json.XML
import groovy.json.JsonSlurper
Map parseXml(String input) {
String json = XML.toJSONObject(input).toString()
new JsonSlurper().parseText(json)
}
But when you have name spacing, it does not get removed.
eg.
<ns2:someObject xmlns:ns2="http://someLink">
<someOtherObject>
<something>SOME_THING</something>
</someOtherObject>
<someOtherObject>
<something>SOME_THING_ELSE</something>
</someOtherObject>
</ns2:someObject>
will end up in
{
"ns2:someObject": {
"xmlns:ns2": "http://someLink",
"someOtherObject": [
{
"something": "SOME_THING"
},
{
"something": "SOME_THING_ELSE"
}
]
}
}
But I want it to end up like this:
{
"someObject": [
{
"something": "SOME_THING"
},
{
"something": "SOME_THING_ELSE"
}
]
}
Does anyone have an idea how I can achive that without reinventing the wheel?
I already found a post a bit similar to mine, but it has a different approach, that's why I asked my question.
The example I gave is just an example, but there dan be multiple entries of someObjects which the given answer in the other post does not include.
Secondly it does iterate over the XML and creates a map of it - that is what I meant with reinventing the wheel. I am sure there must be a library doing exactly that already, so for me it seems wrong to write the parsing code myself.
Many thanks
I am trying to build a bar chart which will allow the user to switch among different datasets (tot1 and tot2) all included in one JSON file:
{
"users":
{
"gender":
{
"tot1":
[
{"label":"female", "value":6038},
{"label":"male", "value":45228},
{"label":"unknown", "value":32932}
]
"tot2":
[
{"label":"female", "value":6022},
{"label":"male", "value":45328},
{"label":"unknown", "value":12932}
]
}
}
}
I don't see how I should proceed. Following the solution to a previous question I would need to select tot1 or tot2 when loading the data with d3.json. Of course the chart specs don't change when switching from tot1 to tot2, so probably the right approach would be to compose the chart with a function which receives the data as an argument...
But if I try to load my data into variables I get an error
data1 = d3.json("../data.json", function(data) {return data.users.gender.tot;});
As input I have list of all objects where each object has properties:
name
children(object.children is the list of all children)
parent(null if object is top level)
How correctly to use Groovy JSONBuilder to render such data(depth of tree is unlimited):
-Object 1
--Object 1.1
---Object 1.1.1
--Object 1.2
-Object 2
in JSON format it should be something like this:
[
{
"name":"Object1",
"children":[
{
"name":"Object1.1",
"children":[
{
"name":"Object 1.1.1",
"children":[]
}
]
},
{
"name":"Object1.2",
"children":[]
}
]
},
{
"name":"Object2","children":[]
}
]
This is needed to build JSON for extJS component which will display this tree. Thanks for your help!
Store this structure in a object say jsonContainer and try following piece of code
render jsonContainer as grails.converters.deep.JSON
Hope this helps.
Add this property to your Config.groovy file:
grails.converters.json.default.deep=true
The Grails Doc
is a little out of date but the relevant property is listed there under 'Configuration Options'