Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

[CHARTS] theme mode changes without refresh.


How can I change theme mode for charts? For example: If user change theme mode to dark from light. How can I update the charts theme mode?


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (3)


Also, I'm getting this error on HTML version of Metronic:

"uncaught ReferenceError: KTUtil is not defined at theme-mode.js:165:1"

I'll "Amcharts pie" and "html headers" code.

" var mode = KTThemeMode.getMode();

am5.ready(function () {
// Create root element
//
var root = am5.Root.new("kt_amcharts_3");
root._logo.dispose();
// Set themes
//
if (mode === "dark") {
root.setThemes([
am5themes_Animated.new(root),
am5themes_Dark.new(root)
]);
}else{
root.setThemes([
am5themes_Animated.new(root),
]);
}

// Create chart
//
var chart = root.container.children.push(am5percent.PieChart.new(root, {
layout: root.verticalLayout,
radius: am5.percent(50), // The texts on the pie can visible when its set to smaller radius. for ex: 50 or 60
paddingRight: 0,
paddingTop: -70,
paddingBottom: 0,
paddingLeft: 0,
}));

// Create series
//
var series = chart.series.push(am5percent.PieSeries.new(root, {
alignLabels: true,
calculateAggregates: true,
valueField: "value",
categoryField: "goal"
}));

series.labels.template.setAll({
maxWidth: 80,
fontSize: 10,
oversizedBehavior: "wrap" // to truncate labels, use "truncate"
});
/* series.slices.template.setAll({
strokeWidth: 1,
stroke: am5.color(0xffffff)
}); */

//series.labelsContainer.set("paddingTop", 30);

// Set up adapters for variable slice radius
//
series.slices.template.adapters.add("radius", function (radius, target) {
var dataItem = target.dataItem;
var high = series.getPrivate("valueHigh");

if (dataItem) {
var value = target.dataItem.get("valueWorking", 0);
return radius * value / high
}
return radius;
});

// Set data
//
series.data.setAll(
[ {
value: 10,
goal: "Push-up"
}, {
value: 9,
goal: "Walk 5K Step"
}, {
value: 6,
goal: "Drink 2L Water"
}, {
value: 5,
goal: "Read a book"
}
]);

// Create legend
//
// Pie chart footer data can be removed if code commented.
/* var legend = chart.children.push(am5.Legend.new(root, {
centerX: am5.p50,
x: am5.p50,
marginTop: 15,
marginBottom: 15
})); */

legend.data.setAll(series.dataItems);

// Play initial series animation
//
series.appear(1000, 100);

});"


"<link href="{% static "assets/plugins/custom/datatables/datatables.bundle.css" %}" rel="stylesheet"
type="text/css"/>
<!--end::Vendor Stylesheets-->
<script src="{% static "assets/plugins/custom/ckeditor/ckeditor-inline.bundle.js" %}"></script>
<!--begin::Global Stylesheets Bundle(mandatory for all pages)-->
<link href="{% static "assets/plugins/global/plugins.bundle.css" %}" rel="stylesheet" type="text/css"/>
<link href="{% static "assets/css/style.bundle.css" %}" rel="stylesheet" type="text/css"/>
<!--end::Global Stylesheets Bundle-->
<script src="
<script src="
<script src="
<script src="
<script src="
<script src="
<script src="{% static "assets/js/layout/theme-mode.js" %}"></script>"

How can I solve this issiue?



Hi,

Please make sure your custom js code is triggered via KTUtil's document ready event when all the core code is loaded and available:


// On document ready
KTUtil.onDOMContentLoaded(function() {
KTAppLayoutBuilder.init();
});


Regards,
Sean



Hi,

Please refer to this example in src/js/widgets/charts/widget-1.js</code.


// Update chart on theme mode change
KTThemeMode.on("kt.thememode.change", function() {
if (chart.rendered) {
chart.self.destroy();
}

initChart(chart);
});


Regards.

Regards.


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(