hi
I want to create a chart like the attached image that uses two levels of labels.
I checked the demo on the site but could not solve the problem. Unfortunately, I did not find anything about this issue in the document.
Thank you for your help
<ejs-chart id="container" load="onChartLoad">
<e-chart-primaryxaxis multiLevelLabels="ViewBag.multiLevelLabels"></e-chart-primaryxaxis>
</ejs-chart>
<script>
onChartLoad = function (args) {
args.chart.primaryXAxis.multiLevelLabels = [
{
border: { type: 'WithoutTopandBottomBorder' }
]
}];
}
</script>
public IActionResult Index()
{
List<ChartMultiLevelLabel> multilevels = new List<ChartMultiLevelLabel>();
ChartMultiLevelLabel one = new ChartMultiLevelLabel();
ChartCategory category = new ChartCategory();
category.Start = "-0.5";
category.End = "1.5";
category.Text = "y1";
//…
List<ChartCategory> categoryOne = new List<ChartCategory>();
categoryOne.Add(category);
//….
one.Categories = categoryOne;
multilevels.Add(one);
ViewBag.multiLevelLabels = multilevels;
return View();
} |
Thank
This method is good, but the problem is that the number is not fixed. For example, it may be as follows. The number will change each time. In this method, the range must be specified manually. What can be done about this problem?
name | value | cat |
x1 | 15 | y1 |
x2 | 18 | y1 |
x3 | 12 | y2 |
x4 | 21 | y2 |
x5 | 66 | y2 |
x6 | 21 | y3 |
x7 | 17 | y1 |
x8 | 19 | y1 |
x9 | 34 | y2 |
var chartObj = document.getElementById("container").ej2_instances[0]; // to create chart instance
chartObj.series[0].dataSource = newData;
chartObj.refresh(); |
I think I could not explain what I meant
In this part of the code
You set the range manually. But a column may be added that makes the constraint larger, and this should be done automatically.
For example, the Y1 range is set from 0.5 to 1.5. If a column is added, this range will no longer be correct and should be -0.5 to 2
I want to explain more fully
We have categories that each category has children. For each category, a new child may be added in the future, which should display the new child column. This way it will not be right
Thank you
Can you help me do this? I will explain below
I created this section in the controller with your help
------------------------------------------------------------------------------------------
ChartCategory category = new ChartCategory(); category.Start = "-0.5"; category.End = "1.5"; category.Text = "y1"; ChartCategory category1 = new ChartCategory(); category1.Start = "1.5"; category1.End = "4.5"; category1.Text = "y2"; ChartCategory category2 = new ChartCategory(); category2.Start = "4.5"; category2.End = "5.5"; category2.Text = "y3"; List categoryOne.Add(category); categoryOne.Add(category1); categoryOne.Add(category2); one.Categories = categoryOne; multilevels.Add(one); |
------------------------------------------------------------------------------------------
How can I create an array in JavaScript from this?
{ start: -0.5, end: 1.5, text: 'y1' }, { start: 1.5, end: 4.5, text: 'y2' }, { start: 4.5, end: 5.5, text: 'y3' } ]
|
I mean do not re-value the categories array. For example, Convert
ChartCategory category = new ChartCategory(); or or List<ChartMultiLevelLabel> multilevels = new List<ChartMultiLevelLabel>(); |
into
categories: [
{ start: -0.5, end: 1.5, text: 'y1' },
{ start: 1.5, end: 4.5, text: 'y2' },
{ start: 4.5, end: 5.5, text: 'y3' }
]
That is, the array categories[] are created from them automatically
<script>
onChartLoad = function (args) {
levels = @Html.Raw(Json.Serialize(@ViewBag.multiLevelLabels));
args.chart.primaryXAxis.multiLevelLabels = [
{
border: { type: 'WithoutTopandBottomBorder' },
categories: [
{ start: parseFloat(levels[0].categories[0].start), end: parseFloat(levels[0].categories[0].end), text: levels[0].categories[0].text },
{ start: parseFloat(levels[0].categories[1].start), end: parseFloat(levels[0].categories[1].end), text: levels[0].categories[1].text },
{ start: parseFloat(levels[0].categories[2].start), end: parseFloat(levels[0].categories[2].end), text: levels[0].categories[2].text }
]
}];
}
</script> |